summaryrefslogtreecommitdiff
path: root/tests/unit_node/http2_test.ts
diff options
context:
space:
mode:
authorCaleb Lloyd <2414837+caleblloyd@users.noreply.github.com>2024-08-30 13:46:17 -0400
committerGitHub <noreply@github.com>2024-08-30 23:16:17 +0530
commit4639ae655e9db396fdf4408961db59372334b69b (patch)
tree2f661d5d296f07284e3a24907a34918f17e6df09 /tests/unit_node/http2_test.ts
parentd71eebba0d1ddc43aaf1e0c41f459deebaddc9f7 (diff)
fix(ext/node): session close during stream setup (#25170)
Signed-off-by: Caleb Lloyd <caleblloyd@gmail.com>
Diffstat (limited to 'tests/unit_node/http2_test.ts')
-rw-r--r--tests/unit_node/http2_test.ts63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/unit_node/http2_test.ts b/tests/unit_node/http2_test.ts
index 8e98bd28d..1dfac8f8c 100644
--- a/tests/unit_node/http2_test.ts
+++ b/tests/unit_node/http2_test.ts
@@ -315,3 +315,66 @@ Deno.test("[node/http2 ClientHttp2Session.socket]", async () => {
client.socket.setTimeout(0);
assertEquals(receivedData, "hello world\n");
});
+
+Deno.test("[node/http2 client] connection states", async () => {
+ const expected = {
+ beforeConnect: { connecting: true, closed: false, destroyed: false },
+ afterConnect: { connecting: false, closed: false, destroyed: false },
+ afterClose: { connecting: false, closed: true, destroyed: false },
+ afterDestroy: { connecting: false, closed: true, destroyed: true },
+ };
+ const actual: Partial<typeof expected> = {};
+
+ const url = "http://127.0.0.1:4246";
+ const connectPromise = Promise.withResolvers<void>();
+ const client = http2.connect(url, {}, () => {
+ connectPromise.resolve();
+ });
+ client.on("error", (err) => console.error(err));
+
+ // close event happens after destory has been called
+ const destroyPromise = Promise.withResolvers<void>();
+ client.on("close", () => {
+ destroyPromise.resolve();
+ });
+
+ actual.beforeConnect = {
+ connecting: client.connecting,
+ closed: client.closed,
+ destroyed: client.destroyed,
+ };
+
+ await connectPromise.promise;
+ actual.afterConnect = {
+ connecting: client.connecting,
+ closed: client.closed,
+ destroyed: client.destroyed,
+ };
+
+ // leave a request open to prevent immediate destroy
+ const req = client.request();
+ req.on("data", () => {});
+ req.on("error", (err) => console.error(err));
+ const reqClosePromise = Promise.withResolvers<void>();
+ req.on("close", () => {
+ reqClosePromise.resolve();
+ });
+
+ client.close();
+ actual.afterClose = {
+ connecting: client.connecting,
+ closed: client.closed,
+ destroyed: client.destroyed,
+ };
+
+ await destroyPromise.promise;
+ actual.afterDestroy = {
+ connecting: client.connecting,
+ closed: client.closed,
+ destroyed: client.destroyed,
+ };
+
+ await reqClosePromise.promise;
+
+ assertEquals(actual, expected);
+});