Skip to content

Commit

Permalink
Add tests for modify_ack_deadline and modify_ack_deadline_with_response
Browse files Browse the repository at this point in the history
* Both these methods should add the "modack start" event to the
  subscribe span
  • Loading branch information
mukund-ananthu committed Sep 18, 2024
1 parent 27edc0f commit e5c89fc
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/unit/pubsub_v1/subscriber/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,48 @@ def test_opentelemetry_nack_with_response(span_exporter):
assert spans[0].events[0].name == "nack start"


def test_opentelemetry_modack(span_exporter):
SUBSCRIPTION = "projects/projectID/subscriptions/subscriptionID"
msg = create_message(b"data", ack_id="ack_id")
opentelemetry_data = SubscribeOpenTelemetry(msg)
opentelemetry_data.start_subscribe_span(
subscription=SUBSCRIPTION,
exactly_once_enabled=False,
ack_id="ack_id",
delivery_attempt=2,
)
msg.opentelemetry_data = opentelemetry_data
msg.modify_ack_deadline(3)
opentelemetry_data.end_subscribe_span()

spans = span_exporter.get_finished_spans()
assert len(spans) == 1

assert len(spans[0].events) == 1
assert spans[0].events[0].name == "modack start"


def test_opentelemetry_modack_with_response(span_exporter):
SUBSCRIPTION = "projects/projectID/subscriptions/subscriptionID"
msg = create_message(b"data", ack_id="ack_id")
opentelemetry_data = SubscribeOpenTelemetry(msg)
opentelemetry_data.start_subscribe_span(
subscription=SUBSCRIPTION,
exactly_once_enabled=False,
ack_id="ack_id",
delivery_attempt=2,
)
msg.opentelemetry_data = opentelemetry_data
msg.modify_ack_deadline_with_response(3)
opentelemetry_data.end_subscribe_span()

spans = span_exporter.get_finished_spans()
assert len(spans) == 1

assert len(spans[0].events) == 1
assert spans[0].events[0].name == "modack start"


def test_ack():
msg = create_message(b"foo", ack_id="bogus_ack_id")
with mock.patch.object(msg._request_queue, "put") as put:
Expand Down

0 comments on commit e5c89fc

Please sign in to comment.