Skip to content

Commit ca50fc9

Browse files
committed
Sort system-test.test_transaction_abort_then_retry_spans spans by create time
1 parent 5fa1c00 commit ca50fc9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tests/system/test_observability_options.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,16 @@ def select_in_txn(txn):
213213
db.run_in_transaction(select_in_txn)
214214

215215
span_list = trace_exporter.get_finished_spans()
216+
# Sort the spans by their start time in the hierarchy.
217+
span_list = sorted(span_list, key=lambda span: span.start_time)
216218
got_span_names = [span.name for span in span_list]
217219
want_span_names = [
220+
"CloudSpanner.Database.run_in_transaction",
218221
"CloudSpanner.CreateSession",
222+
"CloudSpanner.Session.run_in_transaction",
219223
"CloudSpanner.Transaction.execute_streaming_sql",
220224
"CloudSpanner.Transaction.execute_streaming_sql",
221225
"CloudSpanner.Transaction.commit",
222-
"CloudSpanner.Session.run_in_transaction",
223-
"CloudSpanner.Database.run_in_transaction",
224226
]
225227

226228
assert got_span_names == want_span_names
@@ -245,28 +247,28 @@ def select_in_txn(txn):
245247

246248
# Check for the series of events
247249
want_events = [
248-
("Starting Commit", {}),
249-
("Commit Done", {}),
250-
(
251-
"Transaction was aborted in user operation, retrying",
252-
{"delay_seconds": "EPHEMERAL", "cause": "EPHEMERAL", "attempt": 1},
253-
),
254250
("Acquiring session", {"kind": "BurstyPool"}),
255251
("Waiting for a session to become available", {"kind": "BurstyPool"}),
256252
("No sessions available in pool. Creating session", {"kind": "BurstyPool"}),
257253
("Creating Session", {}),
254+
(
255+
"Transaction was aborted in user operation, retrying",
256+
{"delay_seconds": "EPHEMERAL", "cause": "EPHEMERAL", "attempt": 1},
257+
),
258+
("Starting Commit", {}),
259+
("Commit Done", {}),
258260
]
259261
assert got_events == want_events
260262

261263
# Check for the statues.
262264
codes = StatusCode
263265
want_statuses = [
266+
("CloudSpanner.Database.run_in_transaction", codes.OK, None),
264267
("CloudSpanner.CreateSession", codes.OK, None),
268+
("CloudSpanner.Session.run_in_transaction", codes.OK, None),
265269
("CloudSpanner.Transaction.execute_streaming_sql", codes.OK, None),
266270
("CloudSpanner.Transaction.execute_streaming_sql", codes.OK, None),
267271
("CloudSpanner.Transaction.commit", codes.OK, None),
268-
("CloudSpanner.Session.run_in_transaction", codes.OK, None),
269-
("CloudSpanner.Database.run_in_transaction", codes.OK, None),
270272
]
271273
assert got_statuses == want_statuses
272274

0 commit comments

Comments
 (0)