1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(node/net): Server connection callback include socket value (#19779)

This commit is contained in:
Leo Kettmeir 2023-07-19 00:33:43 +02:00 committed by GitHub
parent 51b3534b3d
commit bab0294db6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View file

@ -1,11 +1,13 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import * as net from "node:net";
import { assertEquals } from "../../../test_util/std/testing/asserts.ts";
import {
assert,
assertEquals,
} from "../../../test_util/std/testing/asserts.ts";
import { deferred } from "../../../test_util/std/async/deferred.ts";
import * as path from "../../../test_util/std/path/mod.ts";
import * as http from "node:http";
import { assert } from "../../../test_util/std/testing/asserts.ts";
Deno.test("[node/net] close event emits after error event", async () => {
const socket = net.createConnection(27009, "doesnotexist");
@ -96,3 +98,35 @@ Deno.test({
}
},
});
Deno.test("[node/net] connection event has socket value", async () => {
const p = deferred();
const p2 = deferred();
const server = net.createServer();
server.on("error", p.reject);
server.on("connection", (socket) => {
assert(socket !== undefined);
socket.end();
server.close(() => {
p.resolve();
});
});
server.listen(async () => {
// deno-lint-ignore no-explicit-any
const { port } = server.address() as any;
const conn = await Deno.connect({
port,
transport: "tcp",
});
for await (const _ of conn.readable) {
//
}
p2.resolve();
});
await Promise.all([p, p2]);
});

View file

@ -2374,6 +2374,8 @@ export class Server extends EventEmitter {
socket._server = this;
DTRACE_NET_SERVER_CONNECTION(socket);
return socket;
}
_listen2 = _setupListenHandle;