tests: wait for bwatch block write before stopping in test_db_hook
What changed, and why it matters
This change only adjusts a test to wait for a background bookkeeping process to finish before stopping the node. It is not a security fix for production code; it makes a flaky test more reliable so the test's own database mirror does not miss a late write during shutdown.
No security action needed. Treat as a test reliability improvement. If reviewing, confirm wait_bwatch_caught_up is the idiomatic helper used elsewhere for bwatch synchronization.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies tests/test_plugin.py to add BWATCH_OPTS and call wait_bwatch_caught_up(l1) before l1.stop() in test_db_hook and test_db_hook_multiple. The issue is a test-only race: the bwatch plugin asynchronously writes block-history data to the datastore. If the node stops before that async write completes, the main DB receives the write but the dblog.py mirror plugin may not capture it, causing the post-stop DB comparison to fail. The fix synchronizes the test with bwatch before shutdown.
Changed components
tests/test_plugin.pytests/plugins/dblog.py (indirectly, as part of the test scenario)Inspect captured patch +10 / −2
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 686ddd1b..679b8e0b 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -611,7 +611,8 @@ def test_async_rpcmethod(node_factory, executor):
def test_db_hook(node_factory, executor):
"""This tests the db hook."""
dbfile = os.path.join(node_factory.directory, "dblog.sqlite3")
- l1 = node_factory.get_node(options={'plugin': os.path.join(os.getcwd(), 'tests/plugins/dblog.py'),
+ l1 = node_factory.get_node(options={**BWATCH_OPTS,
+ 'plugin': os.path.join(os.getcwd(), 'tests/plugins/dblog.py'),
'dblog-file': dbfile})
# It should see the db being created, and sometime later actually get
@@ -623,6 +624,10 @@ def test_db_hook(node_factory, executor):
l1.daemon.wait_for_log('plugin-dblog.py: CREATE TABLE version \\(version INTEGER\\)')
l1.daemon.wait_for_log("plugin-dblog.py: initialized.* 'startup': True")
+ # bwatch's first block-history write is async; if we stop before it runs,
+ # the main DB can diverge from dblog's mirror (hook may not run in time).
+ wait_bwatch_caught_up(l1)
+
l1.stop()
# Databases should be identical.
@@ -636,7 +641,8 @@ def test_db_hook(node_factory, executor):
def test_db_hook_multiple(node_factory, executor):
"""This tests the db hook for multiple-plugin case."""
dbfile = os.path.join(node_factory.directory, "dblog.sqlite3")
- l1 = node_factory.get_node(options={'plugin': os.path.join(os.getcwd(), 'tests/plugins/dblog.py'),
+ l1 = node_factory.get_node(options={**BWATCH_OPTS,
+ 'plugin': os.path.join(os.getcwd(), 'tests/plugins/dblog.py'),
'important-plugin': os.path.join(os.getcwd(), 'tests/plugins/dbdummy.py'),
'dblog-file': dbfile})
@@ -649,6 +655,8 @@ def test_db_hook_multiple(node_factory, executor):
l1.daemon.wait_for_log('plugin-dblog.py: CREATE TABLE version \\(version INTEGER\\)')
l1.daemon.wait_for_log("plugin-dblog.py: initialized.* 'startup': True")
+ wait_bwatch_caught_up(l1)
+
l1.stop()
# Databases should be identical.
Why this scored 13/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.