Skip to content

Commit b131e1b

Browse files
committed
Merge bitcoin/bitcoin#32101: Accept unordered tracepoints in interface_usdt_utxocache.py
248fdd8 test: accept unordered tracepoints in... (willcl-ark) Pull request description: We have encountered an instance where the tracepoints were not collected in the same order they were fired (#31951). Tracepoint ordering is not guaranteed in userspace for a number of reasons. As this test does not require a strict collection/processing order collect `expected` and `actual` events into dicts and compare them. This will gracefully handle both the number of events, and out-of-order events should they reoccur in the future. Fixes: #31951 ACKs for top commit: 0xB10C: re-ACK 248fdd8 laanwj: Code review ACK 248fdd8 Tree-SHA512: 78d1aa936194d386d919ed26133aac3af5fc6d3d0b1fe1e767288d9e6226e2c701d640e71e994a63ccd48344bd2a0db508cb353cdd5ce1f644cd6f7313654623
2 parents 8cc6011 + 248fdd8 commit b131e1b

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

test/functional/interface_usdt_utxocache.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,6 @@ def test_add_spent(self):
265265
actual_utxocache_adds = []
266266
actual_utxocache_spents = []
267267

268-
def compare_utxo_with_event(utxo, event):
269-
"""Compare a utxo dict to the event produced by BPF"""
270-
assert_equal(utxo["txid"], bytes(event.txid[::-1]).hex())
271-
assert_equal(utxo["index"], event.index)
272-
assert_equal(utxo["height"], event.height)
273-
assert_equal(utxo["value"], event.value)
274-
assert_equal(utxo["is_coinbase"], event.is_coinbase)
275-
276268
def handle_utxocache_add(_, data, __):
277269
event = ctypes.cast(data, ctypes.POINTER(UTXOCacheChange)).contents
278270
self.log.info(f"handle_utxocache_add(): {event}")
@@ -324,9 +316,28 @@ def handle_utxocache_spent(_, data, __):
324316

325317
self.log.info(
326318
f"check that we successfully traced {EXPECTED_HANDLE_ADD_SUCCESS} adds and {EXPECTED_HANDLE_SPENT_SUCCESS} spent")
327-
for expected_utxo, actual_event in zip(expected_utxocache_adds + expected_utxocache_spents,
328-
actual_utxocache_adds + actual_utxocache_spents):
329-
compare_utxo_with_event(expected_utxo, actual_event)
319+
320+
# Check that all expected tracepoints are recieved, but not the order they were recieved in.
321+
# Tracepoint ordering is not strictly guaranteed, so this comparison avoids intermittent failures in the test.
322+
def cache_event_to_key(event):
323+
return (
324+
bytes(event.txid[::-1]).hex(),
325+
event.index,
326+
event.height,
327+
event.value,
328+
event.is_coinbase
329+
)
330+
331+
expected_add_keys = {(e["txid"], e["index"], e["height"], e["value"], e["is_coinbase"])
332+
for e in expected_utxocache_adds}
333+
expected_spent_keys = {(e["txid"], e["index"], e["height"], e["value"], e["is_coinbase"])
334+
for e in expected_utxocache_spents}
335+
336+
actual_add_keys = {cache_event_to_key(e) for e in actual_utxocache_adds}
337+
actual_spent_keys = {cache_event_to_key(e) for e in actual_utxocache_spents}
338+
339+
assert_equal(expected_add_keys, actual_add_keys)
340+
assert_equal(expected_spent_keys, actual_spent_keys)
330341

331342
bpf.cleanup()
332343

0 commit comments

Comments
 (0)