Skip to content

Commit

Permalink
Implement reconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
boronine committed Oct 15, 2024
1 parent 3a125ea commit 2cc62db
Show file tree
Hide file tree
Showing 2 changed files with 268 additions and 206 deletions.
38 changes: 24 additions & 14 deletions src/h2tunnel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,38 +134,48 @@ async function expect200() {
test("happy-path", async () => {
const stopDummyServer = await createDummyHttpServer();

let tunnelServer = new TunnelServer(serverOptions);
const server = new TunnelServer(serverOptions);
const client = new TunnelClient(clientOptions);
server.start();

// Make a request too early
await expect503();

await tunnelServer.waitUntilListening();
let tunnelClient = new TunnelClient(clientOptions);
await server.waitUntilListening();
client.start();

// Make a request too early
await expect503();

// Wait until client is connected and test 200
await tunnelClient.waitUntilConnected();
await tunnelServer.waitUntilConnected();
await client.waitUntilConnected();
assert.strictEqual(server.state, "connected");
await expect200();

// Restart server while client is running
await tunnelServer.stop();
tunnelServer = new TunnelServer(serverOptions);
await server.stop();
server.start();
await server.waitUntilListening();
await expect503();

// Make sure client reconnected and request succeeds
await tunnelClient.waitUntilConnected();
await tunnelServer.waitUntilConnected();
await client.waitUntilConnected();
assert.strictEqual(server.state, "connected");
await server.waitUntilConnected();
await expect200();

// Restart client while server is running
// await tunnelClient.stop();
// tunnelClient = new TunnelClient(clientOptions);
// // await expect503();
await client.stop();
client.start();

await tunnelClient.stop();
await tunnelServer.stop();
// Make a request too early
await expect503();

// Wait until client reconnected and make a request
await client.waitUntilConnected();
await expect200();

await client.stop();
await server.stop();
await stopDummyServer();
});
Loading

0 comments on commit 2cc62db

Please sign in to comment.