Skip to content

Commit 4a58fab

Browse files
committed
Speed up OTLP proto gRPC exporter tests
Fixes #4013
1 parent 72be755 commit 4a58fab

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def Export(self, request, context):
7777
(
7878
"google.rpc.retryinfo-bin",
7979
RetryInfo(
80-
retry_delay=Duration(seconds=4)
80+
retry_delay=Duration(nanos=int(1e7))
8181
).SerializeToString(),
8282
),
8383
)
@@ -300,15 +300,15 @@ def test_otlp_headers_from_env(self):
300300
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
301301
def test_unavailable(self, mock_sleep, mock_expo):
302302

303-
mock_expo.configure_mock(**{"return_value": [1]})
303+
mock_expo.configure_mock(**{"return_value": [0.01]})
304304

305305
add_LogsServiceServicer_to_server(
306306
LogsServiceServicerUNAVAILABLE(), self.server
307307
)
308308
self.assertEqual(
309309
self.exporter.export([self.log_data_1]), LogExportResult.FAILURE
310310
)
311-
mock_sleep.assert_called_with(1)
311+
mock_sleep.assert_called_with(0.01)
312312

313313
@patch(
314314
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
@@ -324,7 +324,7 @@ def test_unavailable_delay(self, mock_sleep, mock_expo):
324324
self.assertEqual(
325325
self.exporter.export([self.log_data_1]), LogExportResult.FAILURE
326326
)
327-
mock_sleep.assert_called_with(4)
327+
mock_sleep.assert_called_with(0.01)
328328

329329
def test_success(self):
330330
add_LogsServiceServicer_to_server(

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
import threading
16-
import time
1716
from logging import WARNING
17+
from time import time_ns
1818
from types import MethodType
1919
from typing import Sequence
2020
from unittest import TestCase
@@ -163,7 +163,7 @@ def code(self):
163163
def trailing_metadata(self):
164164
return {
165165
"google.rpc.retryinfo-bin": RetryInfo(
166-
retry_delay=Duration(seconds=1)
166+
retry_delay=Duration(nanos=int(1e7))
167167
).SerializeToString()
168168
}
169169

@@ -196,9 +196,9 @@ def _exporting(self) -> str:
196196
# pylint: disable=protected-access
197197
self.assertTrue(otlp_mock_exporter._export_lock.locked())
198198
# delay is 1 second while the default shutdown timeout is 30_000 milliseconds
199-
start_time = time.time()
199+
start_time = time_ns()
200200
otlp_mock_exporter.shutdown()
201-
now = time.time()
201+
now = time_ns()
202202
self.assertGreaterEqual(now, (start_time + 30 / 1000))
203203
# pylint: disable=protected-access
204204
self.assertTrue(otlp_mock_exporter._shutdown)

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
# limitations under the License.
1414

1515
import threading
16-
import time
1716
from concurrent.futures import ThreadPoolExecutor
1817

1918
# pylint: disable=too-many-lines
2019
from logging import WARNING
2120
from os import environ
2221
from os.path import dirname
22+
from time import time_ns
2323
from typing import List
2424
from unittest import TestCase
2525
from unittest.mock import patch
@@ -97,7 +97,7 @@ def Export(self, request, context):
9797
(
9898
"google.rpc.retryinfo-bin",
9999
RetryInfo(
100-
retry_delay=Duration(seconds=4)
100+
retry_delay=Duration(nanos=int(1e7))
101101
).SerializeToString(),
102102
),
103103
)
@@ -423,7 +423,7 @@ def test_otlp_exporter_otlp_compression_unspecified(
423423
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
424424
def test_unavailable(self, mock_sleep, mock_expo):
425425

426-
mock_expo.configure_mock(**{"return_value": [1]})
426+
mock_expo.configure_mock(**{"return_value": [0.01]})
427427

428428
add_MetricsServiceServicer_to_server(
429429
MetricsServiceServicerUNAVAILABLE(), self.server
@@ -432,7 +432,7 @@ def test_unavailable(self, mock_sleep, mock_expo):
432432
self.exporter.export(self.metrics["sum_int"]),
433433
MetricExportResult.FAILURE,
434434
)
435-
mock_sleep.assert_called_with(1)
435+
mock_sleep.assert_called_with(0.01)
436436

437437
@patch(
438438
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
@@ -449,7 +449,7 @@ def test_unavailable_delay(self, mock_sleep, mock_expo):
449449
self.exporter.export(self.metrics["sum_int"]),
450450
MetricExportResult.FAILURE,
451451
)
452-
mock_sleep.assert_called_with(4)
452+
mock_sleep.assert_called_with(0.01)
453453

454454
@patch(
455455
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
@@ -802,9 +802,9 @@ def test_shutdown_wait_last_export(self):
802802
# pylint: disable=protected-access
803803
self.assertTrue(self.exporter._export_lock.locked())
804804
# delay is 4 seconds while the default shutdown timeout is 30_000 milliseconds
805-
start_time = time.time()
805+
start_time = time_ns()
806806
self.exporter.shutdown()
807-
now = time.time()
807+
now = time_ns()
808808
self.assertGreaterEqual(now, (start_time + 30 / 1000))
809809
# pylint: disable=protected-access
810810
self.assertTrue(self.exporter._shutdown)

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
import os
1616
import threading
17-
import time
1817
from concurrent.futures import ThreadPoolExecutor
1918
from logging import WARNING
19+
from time import time_ns
2020
from unittest import TestCase
2121
from unittest.mock import Mock, PropertyMock, patch
2222

@@ -91,7 +91,7 @@ def Export(self, request, context):
9191
(
9292
"google.rpc.retryinfo-bin",
9393
RetryInfo(
94-
retry_delay=Duration(seconds=4)
94+
retry_delay=Duration(nanos=int(1e7))
9595
).SerializeToString(),
9696
),
9797
)
@@ -466,14 +466,14 @@ def test_otlp_headers(self, mock_ssl_channel, mock_secure):
466466
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
467467
def test_unavailable(self, mock_sleep, mock_expo):
468468

469-
mock_expo.configure_mock(**{"return_value": [1]})
469+
mock_expo.configure_mock(**{"return_value": [0.01]})
470470

471471
add_TraceServiceServicer_to_server(
472472
TraceServiceServicerUNAVAILABLE(), self.server
473473
)
474474
result = self.exporter.export([self.span])
475475
self.assertEqual(result, SpanExportResult.FAILURE)
476-
mock_sleep.assert_called_with(1)
476+
mock_sleep.assert_called_with(0.01)
477477

478478
@patch(
479479
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
@@ -489,7 +489,7 @@ def test_unavailable_delay(self, mock_sleep, mock_expo):
489489
self.assertEqual(
490490
self.exporter.export([self.span]), SpanExportResult.FAILURE
491491
)
492-
mock_sleep.assert_called_with(4)
492+
mock_sleep.assert_called_with(0.01)
493493

494494
def test_success(self):
495495
add_TraceServiceServicer_to_server(
@@ -954,9 +954,9 @@ def test_shutdown_wait_last_export(self):
954954
# pylint: disable=protected-access
955955
self.assertTrue(self.exporter._export_lock.locked())
956956
# delay is 4 seconds while the default shutdown timeout is 30_000 milliseconds
957-
start_time = time.time()
957+
start_time = time_ns()
958958
self.exporter.shutdown()
959-
now = time.time()
959+
now = time_ns()
960960
self.assertGreaterEqual(now, (start_time + 30 / 1000))
961961
# pylint: disable=protected-access
962962
self.assertTrue(self.exporter._shutdown)

0 commit comments

Comments
 (0)