Skip to content

Commit 6e1c82a

Browse files
committed
pytest: fix flake in tests/test_connection.py::test_reconnect_signed
Sometimes, l1 wouldn't receive the msg before l2 hung up, causing chaos. What we *actually* want here is to make sure that l1 receives the msg before closing: ``` l1.rpc.connect(l2.info['id'], 'localhost', l2.port) > l1.rpc.fundchannel(l2.info['id'], CHANNEL_SIZE) tests/test_connection.py:667: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ contrib/pyln-client/pyln/client/lightning.py:767: in fundchannel return self.call("fundchannel", payload) contrib/pyln-testing/pyln/testing/utils.py:740: in call res = LightningRpc.call(self, method, payload, cmdprefix, filter) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pyln.testing.utils.PrettyPrintingLightningRpc object at 0x7f22112f5450> method = 'fundchannel' payload = {'amount': 50000, 'announce': True, 'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59'} cmdprefix = None, filter = None def call(self, method, payload=None, cmdprefix=None, filter=None): """Generic call API: you can set cmdprefix here, or set self.cmdprefix before the call is made. """ self.logger.debug("Calling %s with payload %r", method, payload) if payload is None: payload = {} # Filter out arguments that are None if isinstance(payload, dict): payload = {k: v for k, v in payload.items() if v is not None} this_id = self.get_json_id(method, cmdprefix) self.next_id += 1 # FIXME: we open a new socket for every readobj call... sock = UnixSocket(self.socket_path) buf = b'' if self._notify is not None: # Opt into the notifications support self._writeobj(sock, { "jsonrpc": "2.0", "method": "notifications", "id": this_id + "+notify-enable", "params": { "enable": True }, }) # FIXME: Notification schema support? _, buf = self._readobj(sock, buf) request = { "jsonrpc": "2.0", "method": method, "params": payload, "id": this_id, } if filter is None: filter = self._filter if filter is not None: request["filter"] = filter self._writeobj(sock, request) while True: resp, buf = self._readobj(sock, buf) id = resp.get("id", None) meth = resp.get("method", None) if meth == 'message' and self._notify is not None: n = resp['params'] self._notify( message=n.get('message', None), progress=n.get('progress', None), request=request ) continue if meth is None or id is None: break self.logger.debug("Received response for %s call: %r", method, resp) if 'id' in resp and resp['id'] != this_id: raise ValueError("Malformed response, id is not {}: {}.".format(this_id, resp)) sock.close() if not isinstance(resp, dict): raise TypeError("Malformed response, response is not a dictionary %s." % resp) elif "error" in resp: > raise RpcError(method, payload, resp['error']) E pyln.client.lightning.RpcError: RPC call failed: method: fundchannel, payload: {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'amount': 50000, 'announce': True}, error: {'code': -1, 'message': 'Disconnected', 'data': {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'method': 'openchannel_update'}} ``` Signed-off-by: Rusty Russell <[email protected]>
1 parent eb8e97a commit 6e1c82a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tests/test_connection.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,12 @@ def test_disconnect_half_signed_v2(node_factory):
653653
@pytest.mark.openchannel('v2')
654654
def test_reconnect_signed(node_factory):
655655
# This will fail *after* both sides consider channel opening.
656-
disconnects = ['+WIRE_FUNDING_SIGNED']
656+
disconnects = ['<WIRE_FUNDING_SIGNED']
657657
if EXPERIMENTAL_DUAL_FUND:
658-
disconnects = ['+WIRE_COMMITMENT_SIGNED']
658+
disconnects = ['<WIRE_COMMITMENT_SIGNED']
659659

660-
l1 = node_factory.get_node(may_reconnect=True)
661-
l2 = node_factory.get_node(disconnect=disconnects,
662-
may_reconnect=True)
660+
l1 = node_factory.get_node(may_reconnect=True, disconnect=disconnects)
661+
l2 = node_factory.get_node(may_reconnect=True)
663662

664663
l1.fundwallet(2000000)
665664

0 commit comments

Comments
 (0)