Skip to content

Commit

Permalink
Speed up OTLP proto gRPC exporter tests (#4014)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jul 2, 2024
1 parent 72be755 commit 24095f9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def Export(self, request, context):
(
"google.rpc.retryinfo-bin",
RetryInfo(
retry_delay=Duration(seconds=4)
retry_delay=Duration(nanos=int(1e7))
).SerializeToString(),
),
)
Expand Down Expand Up @@ -300,15 +300,15 @@ def test_otlp_headers_from_env(self):
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
def test_unavailable(self, mock_sleep, mock_expo):

mock_expo.configure_mock(**{"return_value": [1]})
mock_expo.configure_mock(**{"return_value": [0.01]})

add_LogsServiceServicer_to_server(
LogsServiceServicerUNAVAILABLE(), self.server
)
self.assertEqual(
self.exporter.export([self.log_data_1]), LogExportResult.FAILURE
)
mock_sleep.assert_called_with(1)
mock_sleep.assert_called_with(0.01)

@patch(
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
Expand All @@ -324,7 +324,7 @@ def test_unavailable_delay(self, mock_sleep, mock_expo):
self.assertEqual(
self.exporter.export([self.log_data_1]), LogExportResult.FAILURE
)
mock_sleep.assert_called_with(4)
mock_sleep.assert_called_with(0.01)

def test_success(self):
add_LogsServiceServicer_to_server(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import threading
import time
from logging import WARNING
from time import time_ns
from types import MethodType
from typing import Sequence
from unittest import TestCase
Expand Down Expand Up @@ -163,7 +163,7 @@ def code(self):
def trailing_metadata(self):
return {
"google.rpc.retryinfo-bin": RetryInfo(
retry_delay=Duration(seconds=1)
retry_delay=Duration(nanos=int(1e7))
).SerializeToString()
}

Expand Down Expand Up @@ -196,9 +196,9 @@ def _exporting(self) -> str:
# pylint: disable=protected-access
self.assertTrue(otlp_mock_exporter._export_lock.locked())
# delay is 1 second while the default shutdown timeout is 30_000 milliseconds
start_time = time.time()
start_time = time_ns()
otlp_mock_exporter.shutdown()
now = time.time()
now = time_ns()
self.assertGreaterEqual(now, (start_time + 30 / 1000))
# pylint: disable=protected-access
self.assertTrue(otlp_mock_exporter._shutdown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.

import threading
import time
from concurrent.futures import ThreadPoolExecutor

# pylint: disable=too-many-lines
from logging import WARNING
from os import environ
from os.path import dirname
from time import time_ns
from typing import List
from unittest import TestCase
from unittest.mock import patch
Expand Down Expand Up @@ -97,7 +97,7 @@ def Export(self, request, context):
(
"google.rpc.retryinfo-bin",
RetryInfo(
retry_delay=Duration(seconds=4)
retry_delay=Duration(nanos=int(1e7))
).SerializeToString(),
),
)
Expand Down Expand Up @@ -423,7 +423,7 @@ def test_otlp_exporter_otlp_compression_unspecified(
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
def test_unavailable(self, mock_sleep, mock_expo):

mock_expo.configure_mock(**{"return_value": [1]})
mock_expo.configure_mock(**{"return_value": [0.01]})

add_MetricsServiceServicer_to_server(
MetricsServiceServicerUNAVAILABLE(), self.server
Expand All @@ -432,7 +432,7 @@ def test_unavailable(self, mock_sleep, mock_expo):
self.exporter.export(self.metrics["sum_int"]),
MetricExportResult.FAILURE,
)
mock_sleep.assert_called_with(1)
mock_sleep.assert_called_with(0.01)

@patch(
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
Expand All @@ -449,7 +449,7 @@ def test_unavailable_delay(self, mock_sleep, mock_expo):
self.exporter.export(self.metrics["sum_int"]),
MetricExportResult.FAILURE,
)
mock_sleep.assert_called_with(4)
mock_sleep.assert_called_with(0.01)

@patch(
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
Expand Down Expand Up @@ -802,9 +802,9 @@ def test_shutdown_wait_last_export(self):
# pylint: disable=protected-access
self.assertTrue(self.exporter._export_lock.locked())
# delay is 4 seconds while the default shutdown timeout is 30_000 milliseconds
start_time = time.time()
start_time = time_ns()
self.exporter.shutdown()
now = time.time()
now = time_ns()
self.assertGreaterEqual(now, (start_time + 30 / 1000))
# pylint: disable=protected-access
self.assertTrue(self.exporter._shutdown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import os
import threading
import time
from concurrent.futures import ThreadPoolExecutor
from logging import WARNING
from time import time_ns
from unittest import TestCase
from unittest.mock import Mock, PropertyMock, patch

Expand Down Expand Up @@ -91,7 +91,7 @@ def Export(self, request, context):
(
"google.rpc.retryinfo-bin",
RetryInfo(
retry_delay=Duration(seconds=4)
retry_delay=Duration(nanos=int(1e7))
).SerializeToString(),
),
)
Expand Down Expand Up @@ -466,14 +466,14 @@ def test_otlp_headers(self, mock_ssl_channel, mock_secure):
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
def test_unavailable(self, mock_sleep, mock_expo):

mock_expo.configure_mock(**{"return_value": [1]})
mock_expo.configure_mock(**{"return_value": [0.01]})

add_TraceServiceServicer_to_server(
TraceServiceServicerUNAVAILABLE(), self.server
)
result = self.exporter.export([self.span])
self.assertEqual(result, SpanExportResult.FAILURE)
mock_sleep.assert_called_with(1)
mock_sleep.assert_called_with(0.01)

@patch(
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
Expand All @@ -489,7 +489,7 @@ def test_unavailable_delay(self, mock_sleep, mock_expo):
self.assertEqual(
self.exporter.export([self.span]), SpanExportResult.FAILURE
)
mock_sleep.assert_called_with(4)
mock_sleep.assert_called_with(0.01)

def test_success(self):
add_TraceServiceServicer_to_server(
Expand Down Expand Up @@ -954,9 +954,9 @@ def test_shutdown_wait_last_export(self):
# pylint: disable=protected-access
self.assertTrue(self.exporter._export_lock.locked())
# delay is 4 seconds while the default shutdown timeout is 30_000 milliseconds
start_time = time.time()
start_time = time_ns()
self.exporter.shutdown()
now = time.time()
now = time_ns()
self.assertGreaterEqual(now, (start_time + 30 / 1000))
# pylint: disable=protected-access
self.assertTrue(self.exporter._shutdown)
Expand Down

0 comments on commit 24095f9

Please sign in to comment.