Skip to content

Commit

Permalink
Add test coverage for Node.js HTTP/2 idleConnectionTimeoutMs
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm committed Jun 26, 2023
1 parent 4df67c9 commit ce58b78
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/connect-node/src/http2-session-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,30 @@ describe("Http2SessionManager", function () {
});
});

describe("with idleConnectionTimeoutMs", function () {
it('should close an idle connection', async function () {
const sm = new Http2SessionManager(server.getUrl(), {
idleConnectionTimeoutMs: 5 // intentionally short for tests
});
const req1 = await sm.request("POST", "/", {}, {});
await new Promise<void>(resolve => {
req1.close(http2.constants.NGHTTP2_NO_ERROR, resolve);
});
expect(sm.state()).toBe("idle");
await new Promise<void>(resolve => setTimeout(resolve, 15)); // wait for idle timeout
expect(sm.state())
.withContext("connection state after waiting for idle timeout")
.toBe("closed");

// new request should open new connection without errors
const req2 = await sm.request("POST", "/", {}, {});
expect(sm.state()).toBe("open");
await new Promise<void>(resolve => {
req2.close(http2.constants.NGHTTP2_NO_ERROR, resolve);
});
});
});

describe("receiving a GOAWAY frame", function () {
describe("with error ENHANCE_YOUR_CALM and debug data too_many_pings", function () {
it("should use double the original pingIntervalMs for a second connection", async function () {
Expand Down

0 comments on commit ce58b78

Please sign in to comment.