summaryrefslogtreecommitdiff
path: root/tests/unit_node/net_test.ts
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2024-07-24 20:33:45 +0900
committerGitHub <noreply@github.com>2024-07-24 20:33:45 +0900
commit199a8ca4c5a8c5b2a060ef6a8912766a6a98d0b7 (patch)
treef285ddbf9fa59687d5d0bc3610152af41f887a30 /tests/unit_node/net_test.ts
parent29934d558c188fdc3406706da19921ca5a389383 (diff)
fix(ext/node/net): emit `error` before `close` when connection is refused (#24656)
Diffstat (limited to 'tests/unit_node/net_test.ts')
-rw-r--r--tests/unit_node/net_test.ts21
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/unit_node/net_test.ts b/tests/unit_node/net_test.ts
index 89a9fb6ba..ebbc749b5 100644
--- a/tests/unit_node/net_test.ts
+++ b/tests/unit_node/net_test.ts
@@ -5,7 +5,7 @@ import { assert, assertEquals } from "@std/assert/mod.ts";
import * as path from "@std/path/mod.ts";
import * as http from "node:http";
-Deno.test("[node/net] close event emits after error event", async () => {
+Deno.test("[node/net] close event emits after error event - when host is not found", async () => {
const socket = net.createConnection(27009, "doesnotexist");
const events: ("error" | "close")[] = [];
const errorEmitted = Promise.withResolvers<void>();
@@ -24,6 +24,25 @@ Deno.test("[node/net] close event emits after error event", async () => {
assertEquals(events, ["error", "close"]);
});
+Deno.test("[node/net] close event emits after error event - when connection is refused", async () => {
+ const socket = net.createConnection(27009, "127.0.0.1");
+ const events: ("error" | "close")[] = [];
+ const errorEmitted = Promise.withResolvers<void>();
+ const closeEmitted = Promise.withResolvers<void>();
+ socket.once("error", () => {
+ events.push("error");
+ errorEmitted.resolve();
+ });
+ socket.once("close", () => {
+ events.push("close");
+ closeEmitted.resolve();
+ });
+ await Promise.all([errorEmitted.promise, closeEmitted.promise]);
+
+ // `error` happens before `close`
+ assertEquals(events, ["error", "close"]);
+});
+
Deno.test("[node/net] the port is available immediately after close callback", async () => {
const deferred = Promise.withResolvers<void>();