Skip to content

Commit

Permalink
fix: Add flaky decorator to test
Browse files Browse the repository at this point in the history
* TO mitigate failures occurring due to non-deterministic order and
  number of OpenTelemetry spans being exported: open-telemetry/opentelemetry-python#4210
  • Loading branch information
mukund-ananthu committed Nov 4, 2024
1 parent d6635a0 commit 7f30539
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
"pytest",
"pytest-cov",
"pytest-asyncio",
"flaky",
]
UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = []
UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = []
UNIT_TEST_DEPENDENCIES: List[str] = []
UNIT_TEST_DEPENDENCIES: List[str] = ["flaky"]
UNIT_TEST_EXTRAS: List[str] = []
UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {}

Expand Down
1 change: 1 addition & 0 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
microgenerator=True,
samples=True,
cov_level=100,
unit_test_extras=["flaky"],
versions=gcp.common.detect_versions(path="./google", default_first=True),
unit_test_python_versions=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"],
system_test_python_versions=["3.12"],
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/pubsub_v1/publisher/test_publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import pytest
import time
from flaky import flaky
from typing import cast, Callable, Any, TypeVar

from opentelemetry import trace
from google.api_core import gapic_v1
Expand All @@ -48,6 +50,9 @@
PublishMessageWrapper,
)

C = TypeVar("C", bound=Callable[..., Any])
typed_flaky = cast(Callable[[C], C], flaky(max_runs=5, min_passes=1))


def _assert_retries_equal(retry, retry2):
# Retry instances cannot be directly compared, because their predicates are
Expand Down Expand Up @@ -264,6 +269,7 @@ def test_opentelemetry_publisher_batching_exception(
sys.version_info < (3, 8),
reason="Open Telemetry not supported below Python version 3.8",
)
@typed_flaky
def test_opentelemetry_flow_control_exception(creds, span_exporter):
publisher_options = types.PublisherOptions(
flow_control=types.PublishFlowControl(
Expand Down

0 comments on commit 7f30539

Please sign in to comment.