MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_optimistic_locking

Function test_optimistic_locking

tests/test_db.py:329–346  ·  view source on GitHub ↗

Have a node run against a DB, then change it under its feet, crashing it. We start a node, wait for it to settle its write so we have a window where we can interfere, and watch the world burn (safely).

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

327
328
329def test_optimistic_locking(node_factory, bitcoind):
330 """Have a node run against a DB, then change it under its feet, crashing it.
331
332 We start a node, wait for it to settle its write so we have a window where
333 we can interfere, and watch the world burn (safely).
334 """
335 l1 = node_factory.get_node(may_fail=True, broken_log='lightningd:')
336
337 sync_blockheight(bitcoind, [l1])
338 l1.rpc.getinfo()
339 time.sleep(1)
340 l1.db.execute("UPDATE vars SET intval = intval + 1 WHERE name = 'data_version';")
341
342 # Now trigger any DB write and we should be crashing.
343 with pytest.raises(RpcError, match=r'Connection to RPC server lost.'):
344 l1.rpc.newaddr()
345
346 assert(l1.daemon.is_in_log(r'Optimistic lock on the database failed'))
347
348
349@unittest.skipIf(os.environ.get('TEST_DB_PROVIDER', None) != 'postgres', "Only applicable to postgres")

Callers

nothing calls this directly

Calls 6

sync_blockheightFunction · 0.90
is_in_logMethod · 0.80
get_nodeMethod · 0.45
getinfoMethod · 0.45
executeMethod · 0.45
newaddrMethod · 0.45

Tested by

no test coverage detected