Skip to content

Commit

Permalink
More comprehensive test for events and attributes for pool.get
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Dec 10, 2024
1 parent e769db4 commit 215613f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
8 changes: 2 additions & 6 deletions tests/system/test_observability_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def select_in_txn(txn):

# Some event attributes are noisy/highly ephemeral
# and can't be directly compared against.
imprecise_event_attributes = ["exception.stacktrace", "delay_seconds"]
imprecise_event_attributes = ["exception.stacktrace", "delay_seconds", "cause"]
for span in span_list:
got_statuses.append(
(span.name, span.status.status_code, span.status.description)
Expand All @@ -249,11 +249,7 @@ def select_in_txn(txn):
("Commit Done", {}),
(
"Transaction was aborted in user operation, retrying",
{
"delay_seconds": "EPHEMERAL",
"cause": "409 Thrown from ClientInterceptor for testing",
"attempt": 1,
},
{"delay_seconds": "EPHEMERAL", "cause": "EPHEMERAL", "attempt": 1},
),
("Acquiring session", {"kind": "BurstyPool"}),
("Waiting for a session to become available", {"kind": "BurstyPool"}),
Expand Down
52 changes: 52 additions & 0 deletions tests/unit/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ def test_spans_bind_get_empty_pool(self):
attributes=TestFixedSizePool.BASE_ATTRIBUTES,
)

span_list = self.get_finished_spans()
got_all_events = []
for span in span_list:
for event in span.events:
got_all_events.append((event.name, event.attributes))
want_all_events = [
("Invalid session pool size(0) <= 0", {"kind": "FixedSizePool"}),
("Acquiring session", {"kind": "FixedSizePool"}),
("Waiting for a session to become available", {"kind": "FixedSizePool"}),
("No sessions available in the pool", {"kind": "FixedSizePool"}),
]
assert got_all_events == want_all_events

def test_spans_pool_bind(self):
# Tests the exception generated from invoking pool.bind when
# you have an empty pool.
Expand Down Expand Up @@ -331,6 +344,45 @@ def test_spans_pool_bind(self):
span=span_list[0],
)

got_all_events = []

# Some event attributes are noisy/highly ephemeral
# and can't be directly compared against.
imprecise_event_attributes = ["exception.stacktrace", "delay_seconds", "cause"]
for span in span_list:
for event in span.events:
evt_attributes = event.attributes.copy()
for attr_name in imprecise_event_attributes:
if attr_name in evt_attributes:
evt_attributes[attr_name] = "EPHEMERAL"

got_all_events.append((event.name, evt_attributes))

want_all_events = [
("Requesting 1 sessions", {"kind": "FixedSizePool"}),
(
"exception",
{
"exception.type": "IndexError",
"exception.message": "pop from empty list",
"exception.stacktrace": "EPHEMERAL",
"exception.escaped": "False",
},
),
("Creating 1 sessions", {"kind": "FixedSizePool"}),
("Created sessions", {"count": 1}),
(
"exception",
{
"exception.type": "IndexError",
"exception.message": "pop from empty list",
"exception.stacktrace": "EPHEMERAL",
"exception.escaped": "False",
},
),
]
assert got_all_events == want_all_events

def test_get_expired(self):
pool = self._make_one(size=4)
database = _Database("name")
Expand Down

0 comments on commit 215613f

Please sign in to comment.