Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix flaky test #1254

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions tests/unit/pubsub_v1/publisher/test_publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,26 @@ def test_opentelemetry_publish(creds, span_exporter):
client.publish(TOPIC, b"message")
spans = span_exporter.get_finished_spans()

# Span 1: Publisher Flow control span
# Span 2: Publisher Batching span
# Publish Create Span would still be active, and hence not exported.
flow_control_span = spans[0]
assert flow_control_span.name == "publisher flow control"
assert flow_control_span.kind == trace.SpanKind.INTERNAL
# Assert the Publisher Flow Control Span has a parent(the Publish Create
# span is still active, and hence unexported. So, the value of parent cannot
# be asserted)
assert flow_control_span.parent is not None

batching_span = spans[1]
assert batching_span.name == "publisher batching"
assert batching_span.kind == trace.SpanKind.INTERNAL
assert batching_span.parent is not None
# Publisher Flow control and batching spans would be ended in the
# publish() function and are deterministically expected to be in the
# list of exported spans. The Publish Create span and Publish RPC span
# are run async and end at a non-deterministic time. Hence,
# asserting that we have atleast two spans(flow control and batching span)
assert len(spans) >= 2
flow_control_span = None
batching_span = None
for span in spans:
if span.name == "publisher flow control":
flow_control_span = span
assert flow_control_span.kind == trace.SpanKind.INTERNAL
assert flow_control_span.parent is not None
if span.name == "publisher batching":
batching_span = span
assert batching_span.kind == trace.SpanKind.INTERNAL
assert batching_span.parent is not None

assert flow_control_span is not None
assert batching_span is not None


def test_init_w_api_endpoint(creds):
Expand Down