From d9fd1a08f224e5f9b693bb745a914e644db827f6 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Wed, 6 Apr 2022 18:44:24 +1000 Subject: [PATCH] test: added test for if the proxies are connected before a `NodeConnection` is made #369 --- tests/nodes/NodeConnection.test.ts | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/nodes/NodeConnection.test.ts b/tests/nodes/NodeConnection.test.ts index 558e2852d3..7f7417b077 100644 --- a/tests/nodes/NodeConnection.test.ts +++ b/tests/nodes/NodeConnection.test.ts @@ -433,6 +433,47 @@ describe(`${NodeConnection.name} test`, () => { }); await conn.destroy(); }); + test('connects to its target but proxies connect first', async () => { + await clientproxy.openConnectionForward( + targetNodeId, + localHost, + targetPort, + ); + const conn = await NodeConnection.createNodeConnection({ + targetNodeId: targetNodeId, + targetHost: localHost, + targetPort: targetPort, + proxy: clientproxy, + keyManager: clientKeyManager, + nodeConnectionManager: dummyNodeConnectionManager, + destroyCallback, + logger: logger, + clientFactory: async (args) => + GRPCClientAgent.createGRPCClientAgent(args), + }); + // Because the connection will not have enough time to compose before we + // attempt to acquire the connection info, we need to wait and poll it + const connInfo = await poll( + async () => { + return serverProxy.getConnectionInfoByProxy(localHost, sourcePort); + }, + (e) => { + if (e instanceof networkErrors.ErrorConnectionNotComposed) return false; + if (e instanceof networkErrors.ErrorConnectionNotRunning) return false; + return true; + }, + ); + expect(connInfo).toBeDefined(); + expect(connInfo).toMatchObject({ + remoteNodeId: sourceNodeId, + remoteCertificates: expect.any(Array), + localHost: localHost, + localPort: targetPort, + remoteHost: localHost, + remotePort: sourcePort, + }); + await conn.destroy(); + }); test('grpcCall after connection drops', async () => { let nodeConnection: NodeConnection | undefined; let polykeyAgent: PolykeyAgent | undefined;