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

Function test_last_stable_connection

tests/test_connection.py:4404–4432  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

4402
4403
4404def test_last_stable_connection(node_factory):
4405 l1, l2 = node_factory.line_graph(2, opts={'may_reconnect': True})
4406
4407 # We wait a minute to be stable.
4408 STABLE_TIME = 60
4409 assert 'last_stable_connection' not in only_one(l1.rpc.listpeerchannels()['channels'])
4410 assert 'last_stable_connection' not in only_one(l2.rpc.listpeerchannels()['channels'])
4411
4412 recon_time = time.time()
4413
4414 # This take a minute, so don't fail if TIMEOUT is set to 10.
4415 wait_for(lambda: 'last_stable_connection' in only_one(l1.rpc.listpeerchannels()['channels']), timeout=STABLE_TIME + 15)
4416 l1stable = only_one(l1.rpc.listpeerchannels()['channels'])['last_stable_connection']
4417 wait_for(lambda: 'last_stable_connection' in only_one(l2.rpc.listpeerchannels()['channels']))
4418 l2stable = only_one(l2.rpc.listpeerchannels()['channels'])['last_stable_connection']
4419
4420 # Disconnect, and/or restart then reconnect.
4421 l1.rpc.disconnect(l2.info['id'], force=True)
4422 recon_time = int(time.time())
4423 l2.restart()
4424 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
4425
4426 assert only_one(l1.rpc.listpeerchannels()['channels'])['last_stable_connection'] == l1stable
4427 assert only_one(l2.rpc.listpeerchannels()['channels'])['last_stable_connection'] == l2stable
4428 wait_for(lambda: only_one(l1.rpc.listpeerchannels()['channels'])['last_stable_connection'] != l1stable, timeout=STABLE_TIME + 15)
4429 wait_for(lambda: only_one(l2.rpc.listpeerchannels()['channels'])['last_stable_connection'] != l2stable)
4430
4431 assert only_one(l1.rpc.listpeerchannels()['channels'])['last_stable_connection'] >= recon_time + STABLE_TIME
4432 assert only_one(l2.rpc.listpeerchannels()['channels'])['last_stable_connection'] >= recon_time + STABLE_TIME
4433
4434
4435@unittest.skipUnless(RUST, 'RUST is not enabled')

Callers

nothing calls this directly

Calls 7

only_oneFunction · 0.90
wait_forFunction · 0.90
line_graphMethod · 0.80
listpeerchannelsMethod · 0.80
restartMethod · 0.80
disconnectMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected