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

Function test_reconnect_channel_peers

tests/test_connection.py:207–241  ·  view source on GitHub ↗
(node_factory, executor)

Source from the content-addressed store, hash-verified

205
206
207def test_reconnect_channel_peers(node_factory, executor):
208 l1 = node_factory.get_node(may_reconnect=True)
209 l2 = node_factory.get_node(may_reconnect=True)
210 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
211
212 l1.fundchannel(l2, 10**6)
213 l2.restart()
214
215 # Should reconnect.
216 wait_for(lambda: only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['connected'])
217 wait_for(lambda: only_one(l2.rpc.listpeers(l1.info['id'])['peers'])['connected'])
218 # Connect command should succeed.
219 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
220
221 # Stop l2 and wait for l1 to notice.
222 l2.stop()
223 wait_for(lambda: not only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['connected'])
224
225 # Now should fail.
226 with pytest.raises(RpcError, match=r'(Connection refused|Bad file descriptor)'):
227 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
228
229 # Wait for exponential backoff to give us a 2 second window.
230 l1.daemon.wait_for_log('Will try reconnect in 2 seconds')
231
232 # It should now succeed when it restarts.
233 l2.start()
234
235 # Multiples should be fine!
236 fut1 = executor.submit(l1.rpc.connect, l2.info['id'], 'localhost', l2.port)
237 fut2 = executor.submit(l1.rpc.connect, l2.info['id'], 'localhost', l2.port)
238 fut3 = executor.submit(l1.rpc.connect, l2.info['id'], 'localhost', l2.port)
239 fut1.result(10)
240 fut2.result(10)
241 fut3.result(10)
242
243
244def test_connection_moved(node_factory, executor):

Callers

nothing calls this directly

Calls 10

wait_forFunction · 0.90
only_oneFunction · 0.90
restartMethod · 0.80
wait_for_logMethod · 0.80
get_nodeMethod · 0.45
connectMethod · 0.45
fundchannelMethod · 0.45
listpeersMethod · 0.45
stopMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected