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)
| 327 | |
| 328 | |
| 329 | def 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") |