From ce58b78cd49dee02cd558a1d7ce47e9f7be320b4 Mon Sep 17 00:00:00 2001 From: Timo Stamm Date: Mon, 26 Jun 2023 16:58:49 +0200 Subject: [PATCH] Add test coverage for Node.js HTTP/2 idleConnectionTimeoutMs --- .../src/http2-session-manager.spec.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/connect-node/src/http2-session-manager.spec.ts b/packages/connect-node/src/http2-session-manager.spec.ts index 005a7f74a..87185b76b 100644 --- a/packages/connect-node/src/http2-session-manager.spec.ts +++ b/packages/connect-node/src/http2-session-manager.spec.ts @@ -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(resolve => { + req1.close(http2.constants.NGHTTP2_NO_ERROR, resolve); + }); + expect(sm.state()).toBe("idle"); + await new Promise(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(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 () {