diff options
author | fanquake <fanquake@gmail.com> | 2023-09-10 14:06:17 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-09-10 14:10:16 +0100 |
commit | c5a63ea56f8347139bd84e1669b378ecfb234c3c (patch) | |
tree | bcff7efe1e14c318f23b7575ce150c538ed012e9 /test/functional/interface_usdt_mempool.py | |
parent | e25af11225d9d94ecf7068bf7a9a359268786fbe (diff) | |
parent | 9f55773a370a0d039e727445ccee6b84e05f562a (diff) | |
download | bitcoin-c5a63ea56f8347139bd84e1669b378ecfb234c3c.tar.xz |
Merge bitcoin/bitcoin#27944: test: various USDT functional test cleanups (27831 follow-ups)
9f55773a370a0d039e727445ccee6b84e05f562a test: refactor: usdt_mempool: store all events (stickies-v)
bc432704505eb165dd86de39ea3434c6fb7a2514 test: refactor: remove unnecessary nonlocal (stickies-v)
326db63a6819813db55ba0d01ab4fe80f7a0d818 test: log sanity check assertion failures (stickies-v)
f5525ad6808df6afc38e5c6e4767ab577e30629c test: store utxocache events (stickies-v)
f1b99ac94fb77340c4d3a5b4bbc3df28009bc773 test: refactor: deduplicate handle_utxocache_* logic (stickies-v)
ad90ba36bd930f00753643cd1fe0af72d1c828c2 test: refactor: rename inbound to is_inbound (stickies-v)
afc0224cdbe73e326addf5fb98a3e95d941f2104 test: refactor: remove unnecessary blocks_checked counter (stickies-v)
Pull request description:
Various cleanups to the USDT functional tests, largely (but not exclusively) follow-ups to https://github.com/bitcoin/bitcoin/pull/27831#pullrequestreview-1491438045. Except for slightly different logging behaviour in "test: store utxocache events" and "test: log sanity check assertion failures", this is a refactor PR, removing unnecessary code and (imo) making it more readable and maintainable.
The rationale for each change is in the corresponding commit message.
Note: except for "test: store utxocache events" (which relies on its parent, and I separated into two commits because we may want the parent but not the child), all commits are stand-alone and I'm okay with dropping one/multiple commits if they turn out to be controversial or undesired.
ACKs for top commit:
0xB10C:
ACK 9f55773a370a0d039e727445ccee6b84e05f562a. Reviewed the code and ran the USDT interface tests. I stepped through the commits and think all changes are reasonable.
Tree-SHA512: 6c37a0265b6c26d4f9552a056a690b8f86f7304bd33b4419febd8b17369cf6af799cb87c16df35d0c2a1b839ad31de24661d4384eafa88816c2051c522fd3bf5
Diffstat (limited to 'test/functional/interface_usdt_mempool.py')
-rwxr-xr-x | test/functional/interface_usdt_mempool.py | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/test/functional/interface_usdt_mempool.py b/test/functional/interface_usdt_mempool.py index 67cf649830..d1e274480c 100755 --- a/test/functional/interface_usdt_mempool.py +++ b/test/functional/interface_usdt_mempool.py @@ -137,9 +137,7 @@ class MempoolTracepointTest(BitcoinTestFramework): """Add a transaction to the mempool and make sure the tracepoint returns the expected txid, vsize, and fee.""" - EXPECTED_ADDED_EVENTS = 1 - handled_added_events = 0 - event = None + events = [] self.log.info("Hooking into mempool:added tracepoint...") node = self.nodes[0] @@ -148,9 +146,7 @@ class MempoolTracepointTest(BitcoinTestFramework): bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0) def handle_added_event(_, data, __): - nonlocal event, handled_added_events - event = bpf["added_events"].event(data) - handled_added_events += 1 + events.append(bpf["added_events"].event(data)) bpf["added_events"].open_perf_buffer(handle_added_event) @@ -165,7 +161,8 @@ class MempoolTracepointTest(BitcoinTestFramework): self.generate(node, 1) self.log.info("Ensuring mempool:added event was handled successfully...") - assert_equal(EXPECTED_ADDED_EVENTS, handled_added_events) + assert_equal(1, len(events)) + event = events[0] assert_equal(bytes(event.hash)[::-1].hex(), tx["txid"]) assert_equal(event.vsize, tx["tx"].get_vsize()) assert_equal(event.fee, fee) @@ -177,9 +174,7 @@ class MempoolTracepointTest(BitcoinTestFramework): """Expire a transaction from the mempool and make sure the tracepoint returns the expected txid, expiry reason, vsize, and fee.""" - EXPECTED_REMOVED_EVENTS = 1 - handled_removed_events = 0 - event = None + events = [] self.log.info("Hooking into mempool:removed tracepoint...") node = self.nodes[0] @@ -188,9 +183,7 @@ class MempoolTracepointTest(BitcoinTestFramework): bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0) def handle_removed_event(_, data, __): - nonlocal event, handled_removed_events - event = bpf["removed_events"].event(data) - handled_removed_events += 1 + events.append(bpf["removed_events"].event(data)) bpf["removed_events"].open_perf_buffer(handle_removed_event) @@ -212,7 +205,8 @@ class MempoolTracepointTest(BitcoinTestFramework): bpf.perf_buffer_poll(timeout=200) self.log.info("Ensuring mempool:removed event was handled successfully...") - assert_equal(EXPECTED_REMOVED_EVENTS, handled_removed_events) + assert_equal(1, len(events)) + event = events[0] assert_equal(bytes(event.hash)[::-1].hex(), txid) assert_equal(event.reason.decode("UTF-8"), "expiry") assert_equal(event.vsize, tx["tx"].get_vsize()) @@ -226,9 +220,7 @@ class MempoolTracepointTest(BitcoinTestFramework): """Replace one and two transactions in the mempool and make sure the tracepoint returns the expected txids, vsizes, and fees.""" - EXPECTED_REPLACED_EVENTS = 1 - handled_replaced_events = 0 - event = None + events = [] self.log.info("Hooking into mempool:replaced tracepoint...") node = self.nodes[0] @@ -237,9 +229,7 @@ class MempoolTracepointTest(BitcoinTestFramework): bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0) def handle_replaced_event(_, data, __): - nonlocal event, handled_replaced_events - event = bpf["replaced_events"].event(data) - handled_replaced_events += 1 + events.append(bpf["replaced_events"].event(data)) bpf["replaced_events"].open_perf_buffer(handle_replaced_event) @@ -261,7 +251,8 @@ class MempoolTracepointTest(BitcoinTestFramework): bpf.perf_buffer_poll(timeout=200) self.log.info("Ensuring mempool:replaced event was handled successfully...") - assert_equal(EXPECTED_REPLACED_EVENTS, handled_replaced_events) + assert_equal(1, len(events)) + event = events[0] assert_equal(bytes(event.replaced_hash)[::-1].hex(), original_tx["txid"]) assert_equal(event.replaced_vsize, original_tx["tx"].get_vsize()) assert_equal(event.replaced_fee, original_fee) @@ -277,9 +268,7 @@ class MempoolTracepointTest(BitcoinTestFramework): """Create an invalid transaction and make sure the tracepoint returns the expected txid, rejection reason, peer id, and peer address.""" - EXPECTED_REJECTED_EVENTS = 1 - handled_rejected_events = 0 - event = None + events = [] self.log.info("Adding P2P connection...") node = self.nodes[0] @@ -291,9 +280,7 @@ class MempoolTracepointTest(BitcoinTestFramework): bpf = BPF(text=MEMPOOL_TRACEPOINTS_PROGRAM, usdt_contexts=[ctx], debug=0) def handle_rejected_event(_, data, __): - nonlocal event, handled_rejected_events - event = bpf["rejected_events"].event(data) - handled_rejected_events += 1 + events.append(bpf["rejected_events"].event(data)) bpf["rejected_events"].open_perf_buffer(handle_rejected_event) @@ -305,7 +292,8 @@ class MempoolTracepointTest(BitcoinTestFramework): bpf.perf_buffer_poll(timeout=200) self.log.info("Ensuring mempool:rejected event was handled successfully...") - assert_equal(EXPECTED_REJECTED_EVENTS, handled_rejected_events) + assert_equal(1, len(events)) + event = events[0] assert_equal(bytes(event.hash)[::-1].hex(), tx["tx"].hash) # The next test is already known to fail, so disable it to avoid # wasting CPU time and developer time. See |