chore(tools): restore node compat test setup script (#18290)

This commit is contained in:
Yoshiya Hinosawa 2023-03-21 22:38:07 +09:00 committed by GitHub
parent c34e26a9d5
commit aa729a42b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
114 changed files with 3182 additions and 7941 deletions

View file

@ -40,6 +40,8 @@
"test_util/std",
"test_util/wpt",
"third_party",
"tools/node_compat/TODO.md",
"tools/node_compat/versions",
"tools/wpt/expectation.json",
"tools/wpt/manifest.json"
],

View file

@ -1,6 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { partition } from "std/collections/mod.ts";
import { join } from "std/path/mod.ts";
import { partition } from "../../../test_util/std/collections/partition.ts";
import { join } from "../../../test_util/std/path/mod.ts";
/**
* The test suite matches the folders inside the `test` folder inside the
@ -35,7 +35,7 @@ export const ignoreList = Object.entries(config.ignore).reduce(
paths.forEach((path) => total.push(new RegExp(join(suite, path))));
return total;
},
[],
[/package\.json/],
);
export function getPathsFromTestSuites(suites: TestSuites): string[] {

View file

@ -100,10 +100,7 @@
"test-zlib-zero-byte.js",
"test-zlib-zero-windowBits.js"
],
"pummel": [
"test-net-bytes-per-incoming-chunk-overhead.js",
"test-net-write-callbacks.js"
],
"pummel": [],
"sequential": [
"test-child-process-exit.js"
]
@ -115,7 +112,7 @@
"dns.js",
"duplexpair.js",
"fixtures.js",
"hijackstdio",
"hijackstdio.js",
"index.mjs",
"internet.js"
],
@ -137,7 +134,6 @@
"agent1-key.pem"
],
"internet": [
"TODO:test-dgram-connect.js",
"test-dns-any.js",
"test-dns-idna2008.js",
"test-dns-ipv4.js",
@ -155,7 +151,6 @@
"test-assert.js",
"test-bad-unicode.js",
"test-btoa-atob.js",
"TODO:test-buffer-alloc.js",
"test-buffer-arraybuffer.js",
"test-buffer-ascii.js",
"test-buffer-badhex.js",
@ -170,7 +165,6 @@
"test-buffer-fakes.js",
"test-buffer-from.js",
"test-buffer-includes.js",
"TODO:test-buffer-indexof.js",
"test-buffer-inheritance.js",
"test-buffer-isencoding.js",
"test-buffer-iterator.js",
@ -186,7 +180,6 @@
"test-buffer-readint.js",
"test-buffer-readuint.js",
"test-buffer-safe-unsafe.js",
"TODO:test-buffer-sharedarraybuffer.js",
"test-buffer-slice.js",
"test-buffer-slow.js",
"test-buffer-swap.js",
@ -194,7 +187,6 @@
"test-buffer-tostring-range.js",
"test-buffer-tostring-rangeerror.js",
"test-buffer-tostring.js",
"TODO:test-buffer-write.js",
"test-buffer-writedouble.js",
"test-buffer-writefloat.js",
"test-buffer-writeint.js",
@ -207,40 +199,29 @@
"test-child-process-double-pipe.js",
"test-child-process-exec-abortcontroller-promisified.js",
"test-child-process-exec-cwd.js",
"TODO:test-child-process-exec-encoding.js",
"test-child-process-exec-env.js",
"test-child-process-exec-error.js",
"test-child-process-exec-kill-throws.js",
"test-child-process-exec-maxbuf.js",
"TODO:test-child-process-exec-std-encoding.js",
"test-child-process-exec-stdout-stderr-data-string.js",
"test-child-process-exec-timeout-expire.js",
"test-child-process-exec-timeout-kill.js",
"TODO:test-child-process-exec-timeout-not-expired.js",
"test-child-process-execFile-promisified-abortController.js",
"test-child-process-execfile-maxbuf.js",
"TODO:test-child-process-execfile.js",
"test-child-process-execfilesync-maxbuf.js",
"test-child-process-execsync-maxbuf.js",
"TODO:test-child-process-exit-code.js",
"test-child-process-flush-stdio.js",
"TODO:test-child-process-ipc.js",
"test-child-process-kill.js",
"test-child-process-set-blocking.js",
"test-child-process-spawn-args.js",
"test-child-process-spawn-event.js",
"test-child-process-spawnsync-args.js",
"TODO:test-child-process-spawnsync-env.js",
"test-child-process-spawnsync-maxbuf.js",
"test-child-process-spawnsync-validation-errors.js",
"test-child-process-spawnsync.js",
"TODO:test-child-process-stdio-inherit.js",
"TODO:test-child-process-stdout-flush-exit.js",
"TODO:test-child-process-stdout-flush.js",
"test-client-request-destroy.js",
"test-console-async-write-error.js",
"test-console-group.js",
"TODO:test-console-instance.js",
"test-console-log-stdio-broken-dest.js",
"test-console-log-throw-primitive.js",
"test-console-no-swallow-stack-overflow.js",
@ -248,73 +229,21 @@
"test-console-table.js",
"test-console-tty-colors.js",
"test-crypto-hmac.js",
"TODO:test-dgram-address.js",
"TODO:test-dgram-bind-default-address.js",
"TODO:test-dgram-bind.js",
"TODO:test-dgram-bytes-length.js",
"test-dgram-close-during-bind.js",
"TODO:test-dgram-close-in-listening.js",
"TODO:test-dgram-close-is-not-callback.js",
"test-dgram-close-signal.js",
"TODO:test-dgram-close.js",
"TODO:test-dgram-connect-send-callback-buffer-length.js",
"TODO:test-dgram-connect-send-callback-buffer.js",
"TODO:test-dgram-connect-send-callback-multi-buffer.js",
"TODO:test-dgram-connect-send-default-host.js",
"TODO:test-dgram-connect-send-empty-array.js",
"TODO:test-dgram-connect-send-empty-buffer.js",
"TODO:test-dgram-connect-send-empty-packet.js",
"TODO:test-dgram-connect-send-multi-buffer-copy.js",
"TODO:test-dgram-connect-send-multi-string-array.js",
"TODO:test-dgram-connect.js",
"TODO:test-dgram-createSocket-type.js",
"TODO:test-dgram-custom-lookup.js",
"TODO:test-dgram-error-message-address.js",
"TODO:test-dgram-implicit-bind.js",
"TODO:test-dgram-ipv6only.js",
"TODO:test-dgram-listen-after-bind.js",
"TODO:test-dgram-msgsize.js",
"TODO:test-dgram-oob-buffer.js",
"TODO:test-dgram-recv-error.js",
"TODO:test-dgram-send-bad-arguments.js",
"TODO:test-dgram-send-callback-buffer-empty-address.js",
"TODO:test-dgram-send-callback-buffer-length-empty-address.js",
"TODO:test-dgram-send-callback-buffer-length.js",
"TODO:test-dgram-send-callback-buffer.js",
"TODO:test-dgram-send-callback-multi-buffer-empty-address.js",
"TODO:test-dgram-send-callback-multi-buffer.js",
"TODO:test-dgram-send-callback-recursive.js",
"TODO:test-dgram-send-cb-quelches-error.js",
"TODO:test-dgram-send-default-host.js",
"TODO:test-dgram-send-empty-array.js",
"TODO:test-dgram-send-empty-buffer.js",
"TODO:test-dgram-send-empty-packet.js",
"TODO:test-dgram-send-error.js",
"TODO:test-dgram-send-invalid-msg-type.js",
"TODO:test-dgram-send-multi-buffer-copy.js",
"TODO:test-dgram-send-multi-string-array.js",
"TODO:test-dgram-socket-buffer-size.js",
"TODO:test-dgram-udp4.js",
"TODO:test-dgram-udp6-link-local-address.js",
"TODO:test-dgram-udp6-send-default-host.js",
"test-diagnostics-channel-has-subscribers.js",
"TODO:test-diagnostics-channel-net.js",
"test-diagnostics-channel-object-channel-pub-sub.js",
"test-diagnostics-channel-pub-sub.js",
"test-diagnostics-channel-symbol-named.js",
"test-diagnostics-channel-udp.js",
"test-dns-lookup.js",
"test-dns-memory-error.js",
"TODO:test-dns-multi-channel.js",
"test-dns-promises-exists.js",
"TODO:test-dns-resolveany.js",
"test-dns-resolvens-typeerror.js",
"test-dns-setservers-type-check.js",
"TODO:test-dns.js",
"test-eval-strict-referenceerror.js",
"test-eval.js",
"test-event-emitter-add-listeners.js",
"TODO:test-event-emitter-check-listener-leaks.js",
"test-event-emitter-emit-context.js",
"test-event-emitter-error-monitor.js",
"test-event-emitter-errors.js",
@ -323,9 +252,6 @@
"test-event-emitter-listener-count.js",
"test-event-emitter-listeners-side-effects.js",
"test-event-emitter-listeners.js",
"TODO:test-event-emitter-max-listeners-warning-for-null.js",
"TODO:test-event-emitter-max-listeners-warning-for-symbol.js",
"TODO:test-event-emitter-max-listeners-warning.js",
"test-event-emitter-max-listeners.js",
"test-event-emitter-method-names.js",
"test-event-emitter-modify-in-emit.js",
@ -383,7 +309,6 @@
"test-fs-readdir.js",
"test-fs-readfile-empty.js",
"test-fs-realpath-native.js",
"TODO:test-fs-rm.js",
"test-fs-rmdir-recursive-sync-warns-not-found.js",
"test-fs-rmdir-recursive-sync-warns-on-file.js",
"test-fs-rmdir-recursive-throws-not-found.js",
@ -392,7 +317,6 @@
"test-fs-rmdir-recursive-warns-on-file.js",
"test-fs-rmdir-recursive.js",
"test-fs-rmdir-type-check.js",
"TODO:test-fs-watch.js",
"test-fs-watchfile.js",
"test-fs-write-buffer.js",
"test-fs-write-file-buffer.js",
@ -410,14 +334,11 @@
"test-fs-write-sync.js",
"test-fs-write.js",
"test-fs-writev-sync.js",
"TODO:test-fs-writev.js",
"test-handle-wrap-close-abort.js",
"test-http-agent-getname.js",
"test-http-client-get-url.js",
"test-http-client-read-in-error.js",
"test-http-outgoing-buffer.js",
"TODO:test-http-outgoing-destroy.js",
"TODO:test-http-outgoing-finish-writable.js",
"test-http-outgoing-internal-headernames-getter.js",
"test-http-outgoing-internal-headernames-setter.js",
"test-http-outgoing-internal-headers.js",
@ -429,84 +350,39 @@
"test-http-url.parse-post.js",
"test-http-url.parse-search.js",
"test-net-access-byteswritten.js",
"TODO:test-net-after-close.js",
"TODO:test-net-allow-half-open.js",
"test-net-better-error-messages-listen-path.js",
"TODO:test-net-better-error-messages-listen.js",
"test-net-better-error-messages-path.js",
"test-net-better-error-messages-port-hostname.js",
"TODO:test-net-bind-twice.js",
"TODO:test-net-buffersize.js",
"TODO:test-net-bytes-written-large.js",
"TODO:test-net-can-reset-timeout.js",
"test-net-connect-after-destroy.js",
"TODO:test-net-connect-buffer.js",
"TODO:test-net-connect-buffer2.js",
"TODO:test-net-connect-call-socket-connect.js",
"test-net-connect-destroy.js",
"test-net-connect-immediate-destroy.js",
"test-net-connect-immediate-finish.js",
"test-net-connect-no-arg.js",
"TODO:test-net-connect-options-ipv6.js",
"TODO:test-net-connect-options-port.js",
"TODO:test-net-dns-custom-lookup.js",
"test-net-dns-error.js",
"TODO:test-net-dns-lookup-skip.js",
"TODO:test-net-dns-lookup.js",
"test-net-during-close.js",
"TODO:test-net-eaddrinuse.js",
"test-net-end-close.js",
"TODO:test-net-end-destroyed.js",
"test-net-end-without-connect.js",
"test-net-isip.js",
"test-net-isipv4.js",
"test-net-isipv6.js",
"TODO:test-net-listen-after-destroying-stdin.js",
"test-net-listen-close-server-callback-is-not-function.js",
"test-net-listen-close-server.js",
"TODO:test-net-listen-error.js",
"test-net-listen-invalid-port.js",
"test-net-listening.js",
"TODO:test-net-local-address-port.js",
"test-net-localerror.js",
"test-net-options-lookup.js",
"TODO:test-net-pause-resume-connecting.js",
"TODO:test-net-persistent-ref-unref.js",
"test-net-pipe-connect-errors.js",
"TODO:test-net-remote-address-port.js",
"TODO:test-net-server-call-listen-multiple-times.js",
"TODO:test-net-server-capture-rejection.js",
"TODO:test-net-server-close.js",
"test-net-server-listen-options-signal.js",
"test-net-server-listen-options.js",
"test-net-server-listen-path.js",
"test-net-server-listen-remove-callback.js",
"TODO:test-net-server-max-connections.js",
"test-net-server-options.js",
"TODO:test-net-server-pause-on-connect.js",
"TODO:test-net-server-try-ports.js",
"test-net-server-unref-persistent.js",
"test-net-server-unref.js",
"TODO:test-net-socket-close-after-end.js",
"TODO:test-net-socket-connect-without-cb.js",
"TODO:test-net-socket-connecting.js",
"TODO:test-net-socket-destroy-send.js",
"test-net-socket-destroy-twice.js",
"TODO:test-net-socket-end-before-connect.js",
"TODO:test-net-socket-end-callback.js",
"test-net-socket-no-halfopen-enforcer.js",
"TODO:test-net-socket-ready-without-cb.js",
"TODO:test-net-socket-timeout.js",
"TODO:test-net-socket-write-after-close.js",
"TODO:test-net-socket-write-error.js",
"TODO:test-net-sync-cork.js",
"test-net-timeout-no-handle.js",
"TODO:test-net-writable.js",
"TODO:test-net-write-after-end-nt.js",
"test-net-write-arguments.js",
"TODO:test-net-write-fully-async-buffer.js",
"TODO:test-net-write-fully-async-hex-string.js",
"TODO:test-net-write-slow.js",
"test-next-tick-doesnt-hang.js",
"test-next-tick-fixed-queue-regression.js",
"test-next-tick-intentional-starvation.js",
@ -515,7 +391,6 @@
"test-next-tick-when-exiting.js",
"test-next-tick.js",
"test-nodeeventtarget.js",
"TODO:test-os.js",
"test-outgoing-message-destroy.js",
"test-outgoing-message-pipe.js",
"test-path-basename.js",
@ -543,19 +418,14 @@
"test-process-uptime.js",
"test-promise-unhandled-silent.js",
"test-promise-unhandled-throw-handler.js",
"TODO:test-punycode.js",
"test-querystring-escape.js",
"test-querystring-maxKeys-non-finite.js",
"test-querystring-multichar-separator.js",
"test-querystring.js",
"TODO:test-readline-csi.js",
"test-readline-emit-keypress-events.js",
"test-readline-interface-escapecodetimeout.js",
"TODO:test-readline-interface.js",
"test-readline-keys.js",
"test-readline-position.js",
"TODO:test-readline-promises-csi.mjs",
"TODO:test-readline-promises-interface.js",
"test-readline-reopen.js",
"test-readline-set-raw-mode.js",
"test-readline-undefined-columns.js",
@ -563,14 +433,12 @@
"test-stdin-from-file-spawn.js",
"test-stream-add-abort-signal.js",
"test-stream-aliases-legacy.js",
"TODO:test-stream-asIndexedPairs.mjs",
"test-stream-auto-destroy.js",
"test-stream-await-drain-writers-in-synchronously-recursion-write.js",
"test-stream-backpressure.js",
"test-stream-big-packet.js",
"test-stream-big-push.js",
"test-stream-buffer-list.js",
"TODO:test-stream-catch-rejections.js",
"test-stream-construct.js",
"test-stream-destroy-event-order.js",
"test-stream-duplex-destroy.js",
@ -640,7 +508,6 @@
"test-stream-readable-unshift.js",
"test-stream-readable-with-unimplemented-_read.js",
"test-stream-readableListening-state.js",
"TODO:test-stream-some-find-every.mjs",
"test-stream-transform-callback-twice.js",
"test-stream-transform-constructor-set-methods.js",
"test-stream-transform-destroy.js",
@ -723,7 +590,6 @@
"test-timers-unref-throw-then-ref.js",
"test-timers-user-call.js",
"test-timers-zero-timeout.js",
"TODO:test-tls-connect-simple.js",
"test-url-domain-ascii-unicode.js",
"test-url-fileurltopath.js",
"test-url-format-invalid-input.js",
@ -798,11 +664,7 @@
"test-tty-stdin-end.js",
"test-tty-stdout-end.js"
],
"pummel": [
"TODO:test-net-bytes-per-incoming-chunk-overhead.js",
"TODO:test-net-pingpong-delay.js",
"TODO:test-net-write-callbacks.js"
],
"pummel": [],
"sequential": [
"test-child-process-exit.js"
]

View file

@ -47,10 +47,9 @@ async function runTest(t: Deno.TestContext, path: string): Promise<void> {
) {
return;
}
const isTodo = path.includes("TODO");
const ignore =
(Deno.build.os === "windows" && windowsIgnorePaths.has(path)) ||
(Deno.build.os === "darwin" && darwinIgnorePaths.has(path)) || isTodo;
(Deno.build.os === "darwin" && darwinIgnorePaths.has(path));
await t.step({
name: `Node.js compatibility "${path}"`,
ignore,
@ -124,8 +123,7 @@ Deno.test("Node.js compatibility", async (t) => {
});
function checkConfigTestFilesOrder(testFileLists: Array<string[]>) {
for (let testFileList of testFileLists) {
testFileList = testFileList.filter((name) => !name.startsWith("TODO:"));
for (const testFileList of testFileLists) {
const sortedTestList = JSON.parse(JSON.stringify(testFileList));
sortedTestList.sort();
if (JSON.stringify(testFileList) !== JSON.stringify(sortedTestList)) {

View file

@ -1,26 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const { addresses } = require('../common/internet');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.connect(common.PORT, addresses.INVALID_HOST, common.mustCall((err) => {
assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN');
client.once('error', common.mustCall((err) => {
assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN');
client.once('connect', common.mustCall(() => client.close()));
client.connect(common.PORT);
}));
client.connect(common.PORT, addresses.INVALID_HOST);
}));

View file

@ -1,34 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
require('../common');
const assert = require('assert');
const sab = new SharedArrayBuffer(24);
const arr1 = new Uint16Array(sab);
const arr2 = new Uint16Array(12);
arr2[0] = 5000;
arr1[0] = 5000;
arr1[1] = 4000;
arr2[1] = 4000;
const arr_buf = Buffer.from(arr1.buffer);
const ar_buf = Buffer.from(arr2.buffer);
assert.deepStrictEqual(arr_buf, ar_buf);
arr1[1] = 6000;
arr2[1] = 6000;
assert.deepStrictEqual(arr_buf, ar_buf);
// Checks for calling Buffer.byteLength on a SharedArrayBuffer.
assert.strictEqual(Buffer.byteLength(sab), sab.byteLength);
Buffer.from({ buffer: sab }); // Should not throw.

View file

@ -1,115 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
[-1, 10].forEach((offset) => {
assert.throws(
() => Buffer.alloc(9).write('foo', offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 && <= 9. Received ${offset}`
}
);
});
const resultMap = new Map([
['utf8', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['ucs2', Buffer.from([102, 0, 111, 0, 111, 0, 0, 0, 0])],
['ascii', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['latin1', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['binary', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['utf16le', Buffer.from([102, 0, 111, 0, 111, 0, 0, 0, 0])],
['base64', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['base64url', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['hex', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
]);
// utf8, ucs2, ascii, latin1, utf16le
const encodings = ['utf8', 'utf-8', 'ucs2', 'ucs-2', 'ascii', 'latin1',
'binary', 'utf16le', 'utf-16le'];
encodings
.reduce((es, e) => es.concat(e, e.toUpperCase()), [])
.forEach((encoding) => {
const buf = Buffer.alloc(9);
const len = Buffer.byteLength('foo', encoding);
assert.strictEqual(buf.write('foo', 0, len, encoding), len);
if (encoding.includes('-'))
encoding = encoding.replace('-', '');
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
});
// base64
['base64', 'BASE64', 'base64url', 'BASE64URL'].forEach((encoding) => {
const buf = Buffer.alloc(9);
const len = Buffer.byteLength('Zm9v', encoding);
assert.strictEqual(buf.write('Zm9v', 0, len, encoding), len);
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
});
// hex
['hex', 'HEX'].forEach((encoding) => {
const buf = Buffer.alloc(9);
const len = Buffer.byteLength('666f6f', encoding);
assert.strictEqual(buf.write('666f6f', 0, len, encoding), len);
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
});
// Invalid encodings
for (let i = 1; i < 10; i++) {
const encoding = String(i).repeat(i);
const error = common.expectsError({
code: 'ERR_UNKNOWN_ENCODING',
name: 'TypeError',
message: `Unknown encoding: ${encoding}`
});
assert.ok(!Buffer.isEncoding(encoding));
assert.throws(() => Buffer.alloc(9).write('foo', encoding), error);
}
// UCS-2 overflow CVE-2018-12115
for (let i = 1; i < 4; i++) {
// Allocate two Buffers sequentially off the pool. Run more than once in case
// we hit the end of the pool and don't get sequential allocations
const x = Buffer.allocUnsafe(4).fill(0);
const y = Buffer.allocUnsafe(4).fill(1);
// Should not write anything, pos 3 doesn't have enough room for a 16-bit char
assert.strictEqual(x.write('ыыыыыы', 3, 'ucs2'), 0);
// CVE-2018-12115 experienced via buffer overrun to next block in the pool
assert.strictEqual(Buffer.compare(y, Buffer.alloc(4, 1)), 0);
}
// Should not write any data when there is no space for 16-bit chars
const z = Buffer.alloc(4, 0);
assert.strictEqual(z.write('\u0001', 3, 'ucs2'), 0);
assert.strictEqual(Buffer.compare(z, Buffer.alloc(4, 0)), 0);
// Make sure longer strings are written up to the buffer end.
assert.strictEqual(z.write('abcd', 2), 2);
assert.deepStrictEqual([...z], [0, 0, 0x61, 0x62]);
// Large overrun could corrupt the process
assert.strictEqual(Buffer.alloc(4)
.write('ыыыыыы'.repeat(100), 3, 'utf16le'), 0);
{
// .write() does not affect the byte after the written-to slice of the Buffer.
// Refs: https://github.com/nodejs/node/issues/26422
const buf = Buffer.alloc(8);
assert.strictEqual(buf.write('ыы', 1, 'utf16le'), 4);
assert.deepStrictEqual([...buf], [0, 0x4b, 0x04, 0x4b, 0x04, 0, 0, 0]);
}

View file

@ -1,88 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
{
// IPv4 Test
const socket = dgram.createSocket('udp4');
socket.on('listening', common.mustCall(() => {
const address = socket.address();
assert.strictEqual(address.address, common.localhostIPv4);
assert.strictEqual(typeof address.port, 'number');
assert.ok(isFinite(address.port));
assert.ok(address.port > 0);
assert.strictEqual(address.family, 'IPv4');
socket.close();
}));
socket.on('error', (err) => {
socket.close();
assert.fail(`Unexpected error on udp4 socket. ${err.toString()}`);
});
socket.bind(0, common.localhostIPv4);
}
if (common.hasIPv6) {
// IPv6 Test
const socket = dgram.createSocket('udp6');
const localhost = '::1';
socket.on('listening', common.mustCall(() => {
const address = socket.address();
assert.strictEqual(address.address, localhost);
assert.strictEqual(typeof address.port, 'number');
assert.ok(isFinite(address.port));
assert.ok(address.port > 0);
assert.strictEqual(address.family, 'IPv6');
socket.close();
}));
socket.on('error', (err) => {
socket.close();
assert.fail(`Unexpected error on udp6 socket. ${err.toString()}`);
});
socket.bind(0, localhost);
}
{
// Verify that address() throws if the socket is not bound.
const socket = dgram.createSocket('udp4');
assert.throws(() => {
socket.address();
}, /^Error: getsockname EBADF$/);
}

View file

@ -1,60 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
// Skip test in FreeBSD jails since 0.0.0.0 will resolve to default interface
if (common.inFreeBSDJail)
common.skip('In a FreeBSD jail');
const assert = require('assert');
const dgram = require('dgram');
dgram.createSocket('udp4').bind(0, common.mustCall(function() {
assert.strictEqual(typeof this.address().port, 'number');
assert.ok(isFinite(this.address().port));
assert.ok(this.address().port > 0);
assert.strictEqual(this.address().address, '0.0.0.0');
this.close();
}));
if (!common.hasIPv6) {
common.printSkipMessage('udp6 part of test, because no IPv6 support');
return;
}
dgram.createSocket('udp6').bind(0, common.mustCall(function() {
assert.strictEqual(typeof this.address().port, 'number');
assert.ok(isFinite(this.address().port));
assert.ok(this.address().port > 0);
let address = this.address().address;
if (address === '::ffff:0.0.0.0')
address = '::';
assert.strictEqual(address, '::');
this.close();
}));

View file

@ -1,50 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.on('listening', common.mustCall(() => {
assert.throws(() => {
socket.bind();
}, {
code: 'ERR_SOCKET_ALREADY_BOUND',
name: 'Error',
message: /^Socket is already bound$/
});
socket.close();
}));
const result = socket.bind(); // Should not throw.
assert.strictEqual(result, socket); // Should have returned itself.

View file

@ -1,46 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const assert = require('assert');
const dgram = require('dgram');
const message = Buffer.from('Some bytes');
const client = dgram.createSocket('udp4');
client.send(
message,
0,
message.length,
41234,
'localhost',
function(err, bytes) {
assert.strictEqual(bytes, message.length);
client.close();
}
);

View file

@ -1,33 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
// Ensure that if a dgram socket is closed before the sendQueue is drained
// will not crash
const common = require('../common');
const dgram = require('dgram');
const buf = Buffer.alloc(1024, 42);
const socket = dgram.createSocket('udp4');
socket.on('listening', function() {
socket.close();
});
// Get a random port for send
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
// Adds a listener to 'listening' to send the data when
// the socket is available
socket.send(buf, 0, buf.length,
portGetter.address().port,
portGetter.address().address);
portGetter.close();
}));

View file

@ -1,28 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const dgram = require('dgram');
const buf = Buffer.alloc(1024, 42);
const socket = dgram.createSocket('udp4');
// Get a random port for send
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
socket.send(buf, 0, buf.length,
portGetter.address().port,
portGetter.address().address);
// If close callback is not function, ignore the argument.
socket.close('bad argument');
portGetter.close();
socket.on('close', common.mustCall());
}));

View file

@ -1,63 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// Flags: --expose-internals
'use strict';
// Ensure that if a dgram socket is closed before the DNS lookup completes, it
// won't crash.
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const { kStateSymbol } = require('internal/dgram');
const buf = Buffer.alloc(1024, 42);
let socket = dgram.createSocket('udp4');
const { handle } = socket[kStateSymbol];
// Get a random port for send
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
socket.send(buf, 0, buf.length,
portGetter.address().port,
portGetter.address().address);
assert.strictEqual(socket.close(common.mustCall()), socket);
socket.on('close', common.mustCall());
socket = null;
// Verify that accessing handle after closure doesn't throw
setImmediate(function() {
setImmediate(function() {
console.log('Handle fd is: ', handle.fd);
});
});
portGetter.close();
}));

View file

@ -1,30 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const offset = 20;
const len = buf.length - offset;
const messageSent = common.mustSucceed(function messageSent(bytes) {
assert.notStrictEqual(bytes, buf.length);
assert.strictEqual(bytes, buf.length - offset);
client.close();
});
client.bind(0, common.mustCall(() => {
client.connect(client.address().port, common.mustCall(() => {
client.send(buf, offset, len, messageSent);
}));
}));

View file

@ -1,27 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const onMessage = common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf.length);
client.close();
});
client.bind(0, common.mustCall(() => {
client.connect(client.address().port, common.mustCall(() => {
client.send(buf, onMessage);
}));
}));

View file

@ -1,36 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const messageSent = common.mustCall((err, bytes) => {
assert.strictEqual(bytes, buf1.length + buf2.length);
});
const buf1 = Buffer.alloc(256, 'x');
const buf2 = Buffer.alloc(256, 'y');
client.on('listening', common.mustCall(() => {
const port = client.address().port;
client.connect(port, common.mustCall(() => {
client.send([buf1, buf2], messageSent);
}));
}));
client.on('message', common.mustCall((buf, info) => {
const expected = Buffer.concat([buf1, buf2]);
assert.ok(buf.equals(expected), 'message was received correctly');
client.close();
}));
client.bind(0);

View file

@ -1,55 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const server = dgram.createSocket('udp4');
const toSend = [Buffer.alloc(256, 'x'),
Buffer.alloc(256, 'y'),
Buffer.alloc(256, 'z'),
'hello'];
const received = [];
server.on('listening', common.mustCall(() => {
const port = server.address().port;
client.connect(port, (err) => {
assert.ifError(err);
client.send(toSend[0], 0, toSend[0].length);
client.send(toSend[1]);
client.send([toSend[2]]);
client.send(toSend[3], 0, toSend[3].length);
client.send(new Uint8Array(toSend[0]), 0, toSend[0].length);
client.send(new Uint8Array(toSend[1]));
client.send([new Uint8Array(toSend[2])]);
client.send(new Uint8Array(Buffer.from(toSend[3])),
0, toSend[3].length);
});
}));
server.on('message', common.mustCall((buf, info) => {
received.push(buf.toString());
if (received.length === toSend.length * 2) {
// The replies may arrive out of order -> sort them before checking.
received.sort();
const expected = toSend.concat(toSend).map(String).sort();
assert.deepStrictEqual(received, expected);
client.close();
server.close();
}
}, toSend.length * 2));
server.bind(0);

View file

@ -1,29 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.on('message', common.mustCall((buf, info) => {
const expected = Buffer.alloc(0);
assert.ok(buf.equals(expected), `Expected empty message but got ${buf}`);
client.close();
}));
client.on('listening', common.mustCall(() => {
client.connect(client.address().port,
common.localhostIPv4,
common.mustCall(() => client.send([])));
}));
client.bind(0);

View file

@ -1,27 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.bind(0, common.mustCall(function() {
const port = this.address().port;
client.connect(port, common.mustCall(() => {
const buf = Buffer.alloc(0);
client.send(buf, 0, 0, common.mustSucceed());
}));
client.on('message', common.mustCall((buffer) => {
assert.strictEqual(buffer.length, 0);
client.close();
}));
}));

View file

@ -1,35 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.bind(0, common.mustCall(function() {
client.connect(client.address().port, common.mustCall(() => {
client.on('message', common.mustCall(callback));
const buf = Buffer.alloc(1);
const interval = setInterval(function() {
client.send(buf, 0, 0, common.mustCall(callback));
}, 10);
function callback(firstArg) {
// If client.send() callback, firstArg should be null.
// If client.on('message') listener, firstArg should be a 0-length buffer.
if (firstArg instanceof Buffer) {
assert.strictEqual(firstArg.length, 0);
clearInterval(interval);
client.close();
}
}
}));
}));

View file

@ -1,36 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const onMessage = common.mustCall(common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf1.length + buf2.length);
}));
const buf1 = Buffer.alloc(256, 'x');
const buf2 = Buffer.alloc(256, 'y');
client.on('listening', common.mustCall(function() {
const toSend = [buf1, buf2];
client.connect(client.address().port, common.mustCall(() => {
client.send(toSend, onMessage);
}));
}));
client.on('message', common.mustCall(function onMessage(buf, info) {
const expected = Buffer.concat([buf1, buf2]);
assert.ok(buf.equals(expected), 'message was received correctly');
client.close();
}));
client.bind(0);

View file

@ -1,24 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
const data = ['foo', 'bar', 'baz'];
socket.on('message', common.mustCall((msg, rinfo) => {
socket.close();
assert.deepStrictEqual(msg.toString(), data.join(''));
}));
socket.bind(0, () => {
socket.connect(socket.address().port, common.mustCall(() => {
socket.send(data);
}));
});

View file

@ -1,73 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const PORT = 12345;
const client = dgram.createSocket('udp4');
client.connect(PORT, common.mustCall(() => {
const remoteAddr = client.remoteAddress();
assert.strictEqual(remoteAddr.port, PORT);
assert.throws(() => {
client.connect(PORT, common.mustNotCall());
}, {
name: 'Error',
message: 'Already connected',
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED'
});
client.disconnect();
assert.throws(() => {
client.disconnect();
}, {
name: 'Error',
message: 'Not connected',
code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED'
});
assert.throws(() => {
client.remoteAddress();
}, {
name: 'Error',
message: 'Not connected',
code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED'
});
client.once('connect', common.mustCall(() => client.close()));
client.connect(PORT);
}));
assert.throws(() => {
client.connect(PORT);
}, {
name: 'Error',
message: 'Already connected',
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED'
});
assert.throws(() => {
client.disconnect();
}, {
name: 'Error',
message: 'Not connected',
code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED'
});
[ 0, null, 78960, undefined ].forEach((port) => {
assert.throws(() => {
client.connect(port);
}, {
name: 'RangeError',
message: /^Port should be > 0 and < 65536/,
code: 'ERR_SOCKET_BAD_PORT'
});
});

View file

@ -1,68 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const invalidTypes = [
'test',
['udp4'],
new String('udp4'),
1,
{},
true,
false,
null,
undefined,
];
const validTypes = [
'udp4',
'udp6',
{ type: 'udp4' },
{ type: 'udp6' },
];
const errMessage = /^Bad socket type specified\. Valid types are: udp4, udp6$/;
// Error must be thrown with invalid types
invalidTypes.forEach((invalidType) => {
assert.throws(() => {
dgram.createSocket(invalidType);
}, {
code: 'ERR_SOCKET_BAD_TYPE',
name: 'TypeError',
message: errMessage
});
});
// Error must not be thrown with valid types
validTypes.forEach((validType) => {
const socket = dgram.createSocket(validType);
socket.close();
});
// Ensure buffer sizes can be set
{
const socket = dgram.createSocket({
type: 'udp4',
recvBufferSize: 10000,
sendBufferSize: 15000
});
socket.bind(common.mustCall(() => {
// note: linux will double the buffer size
assert.ok(socket.getRecvBufferSize() === 10000 ||
socket.getRecvBufferSize() === 20000,
'SO_RCVBUF not 10000 or 20000, ' +
`was ${socket.getRecvBufferSize()}`);
assert.ok(socket.getSendBufferSize() === 15000 ||
socket.getSendBufferSize() === 30000,
'SO_SNDBUF not 15000 or 30000, ' +
`was ${socket.getRecvBufferSize()}`);
socket.close();
}));
}

View file

@ -1,64 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
// IPv4 Test
const socket_ipv4 = dgram.createSocket('udp4');
socket_ipv4.on('listening', common.mustNotCall());
socket_ipv4.on('error', common.mustCall(function(e) {
assert.strictEqual(e.port, undefined);
assert.strictEqual(e.message, 'bind EADDRNOTAVAIL 1.1.1.1');
assert.strictEqual(e.address, '1.1.1.1');
assert.strictEqual(e.code, 'EADDRNOTAVAIL');
socket_ipv4.close();
}));
socket_ipv4.bind(0, '1.1.1.1');
// IPv6 Test
const socket_ipv6 = dgram.createSocket('udp6');
socket_ipv6.on('listening', common.mustNotCall());
socket_ipv6.on('error', common.mustCall(function(e) {
// EAFNOSUPPORT or EPROTONOSUPPORT means IPv6 is disabled on this system.
const allowed = ['EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EPROTONOSUPPORT'];
assert(allowed.includes(e.code), `'${e.code}' was not one of ${allowed}.`);
assert.strictEqual(e.port, undefined);
assert.strictEqual(e.message, `bind ${e.code} 111::1`);
assert.strictEqual(e.address, '111::1');
socket_ipv6.close();
}));
socket_ipv6.bind(0, '111::1');

View file

@ -1,53 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const dgram = require('dgram');
const source = dgram.createSocket('udp4');
const target = dgram.createSocket('udp4');
let messages = 0;
target.on('message', common.mustCall(function(buf) {
if (buf.toString() === 'abc') ++messages;
if (buf.toString() === 'def') ++messages;
if (messages === 2) {
source.close();
target.close();
}
}, 2));
target.on('listening', common.mustCall(function() {
// Second .send() call should not throw a bind error.
const port = this.address().port;
source.send(Buffer.from('abc'), 0, 3, port, '127.0.0.1');
source.send(Buffer.from('def'), 0, 3, port, '127.0.0.1');
}));
target.bind(0);

View file

@ -1,52 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.bind();
let fired = false;
const timer = setTimeout(() => {
socket.close();
}, 100);
socket.on('listening', common.mustCall(() => {
clearTimeout(timer);
fired = true;
socket.close();
}));
socket.on('close', common.mustCall(() => {
assert(fired, 'listening should fire after bind');
}));

View file

@ -1,46 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
// Send a too big datagram. The destination doesn't matter because it's
// not supposed to get sent out anyway.
const buf = Buffer.allocUnsafe(256 * 1024);
const sock = dgram.createSocket('udp4');
sock.send(buf, 0, buf.length, 12345, '127.0.0.1', common.mustCall(cb));
function cb(err) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'EMSGSIZE');
assert.strictEqual(err.address, '127.0.0.1');
assert.strictEqual(err.port, 12345);
assert.strictEqual(err.message, 'send EMSGSIZE 127.0.0.1:12345');
sock.close();
}

View file

@ -1,52 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
// Some operating systems report errors when an UDP message is sent to an
// unreachable host. This error can be reported by sendto() and even by
// recvfrom(). Node should not propagate this error to the user.
const common = require('../common');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
const buf = Buffer.from([1, 2, 3, 4]);
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
const { address, port } = portGetter.address();
portGetter.close(common.mustCall(() => {
socket.send(buf, 0, 0, port, address, common.mustNotCall());
socket.send(buf, 0, 4, port, address, common.mustNotCall());
socket.send(buf, 1, 3, port, address, common.mustNotCall());
socket.send(buf, 3, 1, port, address, common.mustNotCall());
// Since length of zero means nothing, don't error despite OOB.
socket.send(buf, 4, 0, port, address, common.mustNotCall());
socket.close();
}));
}));

View file

@ -1,26 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const { kStateSymbol } = require('internal/dgram');
const s = dgram.createSocket('udp4');
const { handle } = s[kStateSymbol];
s.on('error', common.mustCall((err) => {
s.close();
// Don't check the full error message, as the errno is not important here.
assert.match(String(err), /^Error: recvmsg/);
assert.strictEqual(err.syscall, 'recvmsg');
}));
s.on('message', common.mustNotCall('no message should be received.'));
s.bind(common.mustCall(() => handle.onmessage(-1, handle, null, null)));

View file

@ -1,162 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const buf = Buffer.from('test');
const host = '127.0.0.1';
const sock = dgram.createSocket('udp4');
function checkArgs(connected) {
// First argument should be a buffer.
assert.throws(
() => { sock.send(); },
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "buffer" argument must be of type string or an instance ' +
'of Buffer, TypedArray, or DataView. Received undefined'
}
);
// send(buf, offset, length, port, host)
if (connected) {
assert.throws(
() => { sock.send(buf, 1, 1, -1, host); },
{
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
name: 'Error',
message: 'Already connected'
}
);
assert.throws(
() => { sock.send(buf, 1, 1, 0, host); },
{
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
name: 'Error',
message: 'Already connected'
}
);
assert.throws(
() => { sock.send(buf, 1, 1, 65536, host); },
{
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
name: 'Error',
message: 'Already connected'
}
);
assert.throws(
() => { sock.send(buf, 1234, '127.0.0.1', common.mustNotCall()); },
{
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED',
name: 'Error',
message: 'Already connected'
}
);
const longArray = [1, 2, 3, 4, 5, 6, 7, 8];
for (const input of ['hello',
Buffer.from('hello'),
Buffer.from('hello world').subarray(0, 5),
Buffer.from('hello world').subarray(4, 9),
Buffer.from('hello world').subarray(6),
new Uint8Array([1, 2, 3, 4, 5]),
new Uint8Array(longArray).subarray(0, 5),
new Uint8Array(longArray).subarray(2, 7),
new Uint8Array(longArray).subarray(3),
new DataView(new ArrayBuffer(5), 0),
new DataView(new ArrayBuffer(6), 1),
new DataView(new ArrayBuffer(7), 1, 5)]) {
assert.throws(
() => { sock.send(input, 6, 0); },
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError',
message: '"offset" is outside of buffer bounds',
}
);
assert.throws(
() => { sock.send(input, 0, 6); },
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError',
message: '"length" is outside of buffer bounds',
}
);
assert.throws(
() => { sock.send(input, 3, 4); },
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
name: 'RangeError',
message: '"length" is outside of buffer bounds',
}
);
}
} else {
assert.throws(() => { sock.send(buf, 1, 1, -1, host); }, RangeError);
assert.throws(() => { sock.send(buf, 1, 1, 0, host); }, RangeError);
assert.throws(() => { sock.send(buf, 1, 1, 65536, host); }, RangeError);
}
// send(buf, port, host)
assert.throws(
() => { sock.send(23, 12345, host); },
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "buffer" argument must be of type string or an instance ' +
'of Buffer, TypedArray, or DataView. Received type number (23)'
}
);
// send([buf1, ..], port, host)
assert.throws(
() => { sock.send([buf, 23], 12345, host); },
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "buffer list arguments" argument must be of type string ' +
'or an instance of Buffer, TypedArray, or DataView. ' +
'Received an instance of Array'
}
);
}
checkArgs();
sock.connect(12345, common.mustCall(() => {
checkArgs(true);
sock.close();
}));

View file

@ -1,23 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.alloc(256, 'x');
const onMessage = common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf.length);
client.close();
});
client.bind(0, () => client.send(buf, client.address().port, onMessage));

View file

@ -1,28 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.alloc(256, 'x');
const offset = 20;
const len = buf.length - offset;
const onMessage = common.mustSucceed(function messageSent(bytes) {
assert.notStrictEqual(bytes, buf.length);
assert.strictEqual(bytes, buf.length - offset);
client.close();
});
client.bind(0, () => client.send(buf, offset, len,
client.address().port,
onMessage));

View file

@ -1,50 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const offset = 20;
const len = buf.length - offset;
const messageSent = common.mustSucceed(function messageSent(bytes) {
assert.notStrictEqual(bytes, buf.length);
assert.strictEqual(bytes, buf.length - offset);
client.close();
});
client.bind(0, () => client.send(buf, offset, len,
client.address().port,
'127.0.0.1',
messageSent));

View file

@ -1,26 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const onMessage = common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf.length);
client.close();
});
client.bind(0, () => client.send(buf,
client.address().port,
common.localhostIPv4,
onMessage));

View file

@ -1,34 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const messageSent = common.mustSucceed(function messageSent(bytes) {
assert.strictEqual(bytes, buf1.length + buf2.length);
});
const buf1 = Buffer.alloc(256, 'x');
const buf2 = Buffer.alloc(256, 'y');
client.on('listening', function() {
const port = this.address().port;
client.send([buf1, buf2], port, messageSent);
});
client.on('message', common.mustCall(function onMessage(buf) {
const expected = Buffer.concat([buf1, buf2]);
assert.ok(buf.equals(expected), 'message was received correctly');
client.close();
}));
client.bind(0);

View file

@ -1,34 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const messageSent = common.mustCall((err, bytes) => {
assert.strictEqual(bytes, buf1.length + buf2.length);
});
const buf1 = Buffer.alloc(256, 'x');
const buf2 = Buffer.alloc(256, 'y');
client.on('listening', () => {
const port = client.address().port;
client.send([buf1, buf2], port, common.localhostIPv4, messageSent);
});
client.on('message', common.mustCall((buf, info) => {
const expected = Buffer.concat([buf1, buf2]);
assert.ok(buf.equals(expected), 'message was received correctly');
client.close();
}));
client.bind(0);

View file

@ -1,50 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const chunk = 'abc';
let received = 0;
let sent = 0;
const limit = 10;
let async = false;
let port;
function onsend() {
if (sent++ < limit) {
client.send(chunk, 0, chunk.length, port, common.localhostIPv4, onsend);
} else {
assert.strictEqual(async, true);
}
}
client.on('listening', function() {
port = this.address().port;
process.nextTick(() => {
async = true;
});
onsend();
});
client.on('message', (buf, info) => {
received++;
if (received === limit) {
client.close();
}
});
client.on('close', common.mustCall(function() {
assert.strictEqual(received, limit);
}));
client.bind(0);

View file

@ -1,79 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const toSend = [Buffer.alloc(256, 'x'),
Buffer.alloc(256, 'y'),
Buffer.alloc(256, 'z'),
'hello'];
const received = [];
let totalBytesSent = 0;
let totalBytesReceived = 0;
const arrayBufferViewsCount = common.getArrayBufferViews(
Buffer.from('')
).length;
client.on('listening', common.mustCall(() => {
const port = client.address().port;
client.send(toSend[0], 0, toSend[0].length, port);
client.send(toSend[1], port);
client.send([toSend[2]], port);
client.send(toSend[3], 0, toSend[3].length, port);
totalBytesSent += toSend.map((buf) => buf.length)
.reduce((a, b) => a + b, 0);
for (const msgBuf of common.getArrayBufferViews(toSend[0])) {
client.send(msgBuf, 0, msgBuf.byteLength, port);
totalBytesSent += msgBuf.byteLength;
}
for (const msgBuf of common.getArrayBufferViews(toSend[1])) {
client.send(msgBuf, port);
totalBytesSent += msgBuf.byteLength;
}
for (const msgBuf of common.getArrayBufferViews(toSend[2])) {
client.send([msgBuf], port);
totalBytesSent += msgBuf.byteLength;
}
}));
client.on('message', common.mustCall((buf, info) => {
received.push(buf.toString());
totalBytesReceived += info.size;
if (totalBytesReceived === totalBytesSent) {
client.close();
}
// For every buffer in `toSend`, we send the raw Buffer,
// as well as every TypedArray in getArrayBufferViews()
}, toSend.length + (toSend.length - 1) * arrayBufferViewsCount));
client.on('close', common.mustCall((buf, info) => {
// The replies may arrive out of order -> sort them before checking.
received.sort();
const repeated = [...toSend];
for (let i = 0; i < arrayBufferViewsCount; i++) {
repeated.push(...toSend.slice(0, 3));
}
assert.strictEqual(totalBytesSent, totalBytesReceived);
const expected = repeated.map(String).sort();
assert.deepStrictEqual(received, expected);
}));
client.bind(0);

View file

@ -1,32 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
let interval;
client.on('message', common.mustCall(function onMessage(buf, info) {
const expected = Buffer.alloc(0);
assert.ok(buf.equals(expected), `Expected empty message but got ${buf}`);
clearInterval(interval);
client.close();
}));
client.on('listening', common.mustCall(function() {
interval = setInterval(function() {
client.send([], client.address().port, common.localhostIPv4);
}, 10);
}));
client.bind(0);

View file

@ -1,50 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.bind(0, common.mustCall(function() {
const port = this.address().port;
client.on('message', common.mustCall(function onMessage(buffer) {
assert.strictEqual(buffer.length, 0);
clearInterval(interval);
client.close();
}));
const buf = Buffer.alloc(0);
const interval = setInterval(function() {
client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall());
}, 10);
}));

View file

@ -1,36 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.bind(0, common.mustCall(function() {
client.on('message', common.mustCall(callback));
const port = this.address().port;
const buf = Buffer.alloc(1);
const interval = setInterval(function() {
client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(callback));
}, 10);
function callback(firstArg) {
// If client.send() callback, firstArg should be null.
// If client.on('message') listener, firstArg should be a 0-length buffer.
if (firstArg instanceof Buffer) {
assert.strictEqual(firstArg.length, 0);
clearInterval(interval);
client.close();
}
}
}));

View file

@ -1,77 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const { internalBinding } = require('internal/test/binding');
const { UV_UNKNOWN } = internalBinding('uv');
const { getSystemErrorName } = require('util');
const { kStateSymbol } = require('internal/dgram');
const mockError = new Error('mock DNS error');
function getSocket(callback) {
const socket = dgram.createSocket('udp4');
socket.on('message', common.mustNotCall('Should not receive any messages.'));
socket.bind(common.mustCall(() => {
socket[kStateSymbol].handle.lookup = function(address, callback) {
process.nextTick(callback, mockError);
};
callback(socket);
}));
return socket;
}
getSocket((socket) => {
socket.on('error', common.mustCall((err) => {
socket.close();
assert.strictEqual(err, mockError);
}));
socket.send('foo', socket.address().port, 'localhost');
});
getSocket((socket) => {
const callback = common.mustCall((err) => {
socket.close();
assert.strictEqual(err, mockError);
});
socket.send('foo', socket.address().port, 'localhost', callback);
});
{
const socket = dgram.createSocket('udp4');
socket.on('message', common.mustNotCall('Should not receive any messages.'));
socket.bind(common.mustCall(() => {
const port = socket.address().port;
const callback = common.mustCall((err) => {
socket.close();
assert.strictEqual(err.code, 'UNKNOWN');
assert.strictEqual(getSystemErrorName(err.errno), 'UNKNOWN');
assert.strictEqual(err.syscall, 'send');
assert.strictEqual(err.address, common.localhostIPv4);
assert.strictEqual(err.port, port);
assert.strictEqual(
err.message,
`${err.syscall} ${err.code} ${err.address}:${err.port}`
);
});
socket[kStateSymbol].handle.send = function() {
return UV_UNKNOWN;
};
socket.send('foo', port, common.localhostIPv4, callback);
}));
}

View file

@ -1,43 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
// This test ensures that a TypeError is raised when the argument to `send()`
// or `sendto()` is anything but a Buffer.
// https://github.com/nodejs/node-v0.x-archive/issues/4496
const assert = require('assert');
const dgram = require('dgram');
// Should throw but not crash.
const socket = dgram.createSocket('udp4');
assert.throws(function() { socket.send(true, 0, 1, 1, 'host'); }, TypeError);
assert.throws(function() { socket.sendto(5, 0, 1, 1, 'host'); }, TypeError);
socket.close();

View file

@ -1,35 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const onMessage = common.mustCall(function(err, bytes) {
assert.strictEqual(bytes, buf1.length + buf2.length);
});
const buf1 = Buffer.alloc(256, 'x');
const buf2 = Buffer.alloc(256, 'y');
client.on('listening', function() {
const toSend = [buf1, buf2];
client.send(toSend, this.address().port, common.localhostIPv4, onMessage);
toSend.splice(0, 2);
});
client.on('message', common.mustCall(function onMessage(buf, info) {
const expected = Buffer.concat([buf1, buf2]);
assert.ok(buf.equals(expected), 'message was received correctly');
client.close();
}));
client.bind(0);

View file

@ -1,20 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
const data = ['foo', 'bar', 'baz'];
socket.on('message', common.mustCall((msg, rinfo) => {
socket.close();
assert.deepStrictEqual(msg.toString(), data.join(''));
}));
socket.bind(() => socket.send(data, socket.address().port, 'localhost'));

View file

@ -1,59 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const message_to_send = 'A message to send';
const server = dgram.createSocket('udp4');
server.on('message', common.mustCall((msg, rinfo) => {
assert.strictEqual(rinfo.address, common.localhostIPv4);
assert.strictEqual(msg.toString(), message_to_send.toString());
server.send(msg, 0, msg.length, rinfo.port, rinfo.address);
}));
server.on('listening', common.mustCall(() => {
const client = dgram.createSocket('udp4');
const port = server.address().port;
client.on('message', common.mustCall((msg, rinfo) => {
assert.strictEqual(rinfo.address, common.localhostIPv4);
assert.strictEqual(rinfo.port, port);
assert.strictEqual(msg.toString(), message_to_send.toString());
client.close();
server.close();
}));
client.send(message_to_send,
0,
message_to_send.length,
port,
'localhost');
client.on('close', common.mustCall());
}));
server.on('close', common.mustCall());
server.bind(0);

View file

@ -1,83 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
if (!common.hasIPv6)
common.skip('no IPv6 support');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp6');
const toSend = [Buffer.alloc(256, 'x'),
Buffer.alloc(256, 'y'),
Buffer.alloc(256, 'z'),
'hello'];
const received = [];
let totalBytesSent = 0;
let totalBytesReceived = 0;
const arrayBufferViewLength = common.getArrayBufferViews(
Buffer.from('')
).length;
client.on('listening', common.mustCall(() => {
const port = client.address().port;
client.send(toSend[0], 0, toSend[0].length, port);
client.send(toSend[1], port);
client.send([toSend[2]], port);
client.send(toSend[3], 0, toSend[3].length, port);
totalBytesSent += toSend.map((buf) => buf.length)
.reduce((a, b) => a + b, 0);
for (const msgBuf of common.getArrayBufferViews(toSend[0])) {
client.send(msgBuf, 0, msgBuf.byteLength, port);
totalBytesSent += msgBuf.byteLength;
}
for (const msgBuf of common.getArrayBufferViews(toSend[1])) {
client.send(msgBuf, port);
totalBytesSent += msgBuf.byteLength;
}
for (const msgBuf of common.getArrayBufferViews(toSend[2])) {
client.send([msgBuf], port);
totalBytesSent += msgBuf.byteLength;
}
}));
client.on('message', common.mustCall((buf, info) => {
received.push(buf.toString());
totalBytesReceived += info.size;
if (totalBytesReceived === totalBytesSent) {
client.close();
}
// For every buffer in `toSend`, we send the raw Buffer,
// as well as every TypedArray in getArrayBufferViews()
}, toSend.length + (toSend.length - 1) * arrayBufferViewLength));
client.on('close', common.mustCall((buf, info) => {
// The replies may arrive out of order -> sort them before checking.
received.sort();
const repeated = [...toSend];
for (let i = 0; i < arrayBufferViewLength; i++) {
// We get arrayBufferViews only for toSend[0..2].
repeated.push(...toSend.slice(0, 3));
}
assert.strictEqual(totalBytesSent, totalBytesReceived);
const expected = repeated.map(String).sort();
assert.deepStrictEqual(received, expected);
}));
client.bind(0);

View file

@ -1,32 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const dc = require('diagnostics_channel');
const isNetSocket = (socket) => socket instanceof net.Socket;
dc.subscribe('net.client.socket', common.mustCall(({ socket }) => {
assert.strictEqual(isNetSocket(socket), true);
}));
dc.subscribe('net.server.socket', common.mustCall(({ socket }) => {
assert.strictEqual(isNetSocket(socket), true);
}));
const server = net.createServer(common.mustCall((socket) => {
socket.destroy();
server.close();
}));
server.listen(() => {
const { port } = server.address();
net.connect(port);
});

View file

@ -1,59 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const dnstools = require('../common/dns');
const { Resolver } = require('dns');
const assert = require('assert');
const dgram = require('dgram');
const servers = [
{
socket: dgram.createSocket('udp4'),
reply: { type: 'A', address: '1.2.3.4', ttl: 123, domain: 'example.org' }
},
{
socket: dgram.createSocket('udp4'),
reply: { type: 'A', address: '5.6.7.8', ttl: 123, domain: 'example.org' }
},
];
let waiting = servers.length;
for (const { socket, reply } of servers) {
socket.on('message', common.mustCall((msg, { address, port }) => {
const parsed = dnstools.parseDNSPacket(msg);
const domain = parsed.questions[0].domain;
assert.strictEqual(domain, 'example.org');
socket.send(dnstools.writeDNSPacket({
id: parsed.id,
questions: parsed.questions,
answers: [reply],
}), port, address);
}));
socket.bind(0, common.mustCall(() => {
if (--waiting === 0) ready();
}));
}
function ready() {
const resolvers = servers.map((server) => ({
server,
resolver: new Resolver()
}));
for (const { server: { socket, reply }, resolver } of resolvers) {
resolver.setServers([`127.0.0.1:${socket.address().port}`]);
resolver.resolve4('example.org', common.mustSucceed((res) => {
assert.deepStrictEqual(res, [reply.address]);
socket.close();
}));
}
}

View file

@ -1,110 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const events = require('events');
// default
{
const e = new events.EventEmitter();
for (let i = 0; i < 10; i++) {
e.on('default', common.mustNotCall());
}
assert.ok(!Object.hasOwn(e._events.default, 'warned'));
e.on('default', common.mustNotCall());
assert.ok(e._events.default.warned);
// symbol
const symbol = Symbol('symbol');
e.setMaxListeners(1);
e.on(symbol, common.mustNotCall());
assert.ok(!Object.hasOwn(e._events[symbol], 'warned'));
e.on(symbol, common.mustNotCall());
assert.ok(Object.hasOwn(e._events[symbol], 'warned'));
// specific
e.setMaxListeners(5);
for (let i = 0; i < 5; i++) {
e.on('specific', common.mustNotCall());
}
assert.ok(!Object.hasOwn(e._events.specific, 'warned'));
e.on('specific', common.mustNotCall());
assert.ok(e._events.specific.warned);
// only one
e.setMaxListeners(1);
e.on('only one', common.mustNotCall());
assert.ok(!Object.hasOwn(e._events['only one'], 'warned'));
e.on('only one', common.mustNotCall());
assert.ok(Object.hasOwn(e._events['only one'], 'warned'));
// unlimited
e.setMaxListeners(0);
for (let i = 0; i < 1000; i++) {
e.on('unlimited', common.mustNotCall());
}
assert.ok(!Object.hasOwn(e._events.unlimited, 'warned'));
}
// process-wide
{
events.EventEmitter.defaultMaxListeners = 42;
const e = new events.EventEmitter();
for (let i = 0; i < 42; ++i) {
e.on('fortytwo', common.mustNotCall());
}
assert.ok(!Object.hasOwn(e._events.fortytwo, 'warned'));
e.on('fortytwo', common.mustNotCall());
assert.ok(Object.hasOwn(e._events.fortytwo, 'warned'));
delete e._events.fortytwo.warned;
events.EventEmitter.defaultMaxListeners = 44;
e.on('fortytwo', common.mustNotCall());
assert.ok(!Object.hasOwn(e._events.fortytwo, 'warned'));
e.on('fortytwo', common.mustNotCall());
assert.ok(Object.hasOwn(e._events.fortytwo, 'warned'));
}
// But _maxListeners still has precedence over defaultMaxListeners
{
events.EventEmitter.defaultMaxListeners = 42;
const e = new events.EventEmitter();
e.setMaxListeners(1);
e.on('uno', common.mustNotCall());
assert.ok(!Object.hasOwn(e._events.uno, 'warned'));
e.on('uno', common.mustNotCall());
assert.ok(Object.hasOwn(e._events.uno, 'warned'));
// chainable
assert.strictEqual(e, e.setMaxListeners(1));
}

View file

@ -1,30 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Flags: --no-warnings
// The flag suppresses stderr output but the warning event will still emit
'use strict';
const common = require('../common');
const events = require('events');
const assert = require('assert');
const e = new events.EventEmitter();
e.setMaxListeners(1);
process.on('warning', common.mustCall((warning) => {
assert.ok(warning instanceof Error);
assert.strictEqual(warning.name, 'MaxListenersExceededWarning');
assert.strictEqual(warning.emitter, e);
assert.strictEqual(warning.count, 2);
assert.strictEqual(warning.type, null);
assert.ok(warning.message.includes(
'2 null listeners added to [EventEmitter].'));
}));
e.on(null, () => {});
e.on(null, () => {});

View file

@ -1,32 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Flags: --no-warnings
// The flag suppresses stderr output but the warning event will still emit
'use strict';
const common = require('../common');
const events = require('events');
const assert = require('assert');
const symbol = Symbol('symbol');
const e = new events.EventEmitter();
e.setMaxListeners(1);
process.on('warning', common.mustCall((warning) => {
assert.ok(warning instanceof Error);
assert.strictEqual(warning.name, 'MaxListenersExceededWarning');
assert.strictEqual(warning.emitter, e);
assert.strictEqual(warning.count, 2);
assert.strictEqual(warning.type, symbol);
assert.ok(warning.message.includes(
'2 Symbol(symbol) listeners added to [EventEmitter].'));
}));
e.on(symbol, () => {});
e.on(symbol, () => {});

View file

@ -1,38 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Flags: --no-warnings
// The flag suppresses stderr output but the warning event will still emit
'use strict';
const common = require('../common');
const events = require('events');
const assert = require('assert');
class FakeInput extends events.EventEmitter {
resume() {}
pause() {}
write() {}
end() {}
}
const e = new FakeInput();
e.setMaxListeners(1);
process.on('warning', common.mustCall((warning) => {
assert.ok(warning instanceof Error);
assert.strictEqual(warning.name, 'MaxListenersExceededWarning');
assert.strictEqual(warning.emitter, e);
assert.strictEqual(warning.count, 2);
assert.strictEqual(warning.type, 'event-type');
assert.ok(warning.message.includes(
'2 event-type listeners added to [FakeInput].'));
}));
e.on('event-type', () => {});
e.on('event-type', () => {}); // Trigger warning.
e.on('event-type', () => {}); // Verify that warning is emitted only once.

View file

@ -1,433 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Flags: --expose-internals
'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { pathToFileURL } = require('url');
const { execSync } = require('child_process');
const { validateRmOptionsSync } = require('internal/fs/utils');
tmpdir.refresh();
let count = 0;
const nextDirPath = (name = 'rm') =>
path.join(tmpdir.path, `${name}-${count++}`);
const isGitPresent = (() => {
try { execSync('git --version'); return true; } catch { return false; }
})();
function gitInit(gitDirectory) {
fs.mkdirSync(gitDirectory);
execSync('git init', common.mustNotMutateObjectDeep({ cwd: gitDirectory }));
}
function makeNonEmptyDirectory(depth, files, folders, dirname, createSymLinks) {
fs.mkdirSync(dirname, common.mustNotMutateObjectDeep({ recursive: true }));
fs.writeFileSync(path.join(dirname, 'text.txt'), 'hello', 'utf8');
const options = common.mustNotMutateObjectDeep({ flag: 'wx' });
for (let f = files; f > 0; f--) {
fs.writeFileSync(path.join(dirname, `f-${depth}-${f}`), '', options);
}
if (createSymLinks) {
// Valid symlink
fs.symlinkSync(
`f-${depth}-1`,
path.join(dirname, `link-${depth}-good`),
'file'
);
// Invalid symlink
fs.symlinkSync(
'does-not-exist',
path.join(dirname, `link-${depth}-bad`),
'file'
);
}
// File with a name that looks like a glob
fs.writeFileSync(path.join(dirname, '[a-z0-9].txt'), '', options);
depth--;
if (depth <= 0) {
return;
}
for (let f = folders; f > 0; f--) {
fs.mkdirSync(
path.join(dirname, `folder-${depth}-${f}`),
{ recursive: true }
);
makeNonEmptyDirectory(
depth,
files,
folders,
path.join(dirname, `d-${depth}-${f}`),
createSymLinks
);
}
}
function removeAsync(dir) {
// Removal should fail without the recursive option.
fs.rm(dir, common.mustCall((err) => {
assert.strictEqual(err.syscall, 'rm');
// Removal should fail without the recursive option set to true.
fs.rm(dir, common.mustNotMutateObjectDeep({ recursive: false }), common.mustCall((err) => {
assert.strictEqual(err.syscall, 'rm');
// Recursive removal should succeed.
fs.rm(dir, common.mustNotMutateObjectDeep({ recursive: true }), common.mustSucceed(() => {
// Attempted removal should fail now because the directory is gone.
fs.rm(dir, common.mustCall((err) => {
assert.strictEqual(err.syscall, 'stat');
}));
}));
}));
}));
}
// Test the asynchronous version
{
// Create a 4-level folder hierarchy including symlinks
let dir = nextDirPath();
makeNonEmptyDirectory(4, 10, 2, dir, true);
removeAsync(dir);
// Create a 2-level folder hierarchy without symlinks
dir = nextDirPath();
makeNonEmptyDirectory(2, 10, 2, dir, false);
removeAsync(dir);
// Same test using URL instead of a path
dir = nextDirPath();
makeNonEmptyDirectory(2, 10, 2, dir, false);
removeAsync(pathToFileURL(dir));
// Create a flat folder including symlinks
dir = nextDirPath();
makeNonEmptyDirectory(1, 10, 2, dir, true);
removeAsync(dir);
// Should fail if target does not exist
fs.rm(
path.join(tmpdir.path, 'noexist.txt'),
common.mustNotMutateObjectDeep({ recursive: true }),
common.mustCall((err) => {
assert.strictEqual(err.code, 'ENOENT');
})
);
// Should delete a file
const filePath = path.join(tmpdir.path, 'rm-async-file.txt');
fs.writeFileSync(filePath, '');
fs.rm(filePath, common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall((err) => {
try {
assert.strictEqual(err, null);
assert.strictEqual(fs.existsSync(filePath), false);
} finally {
fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true }));
}
}));
}
// Removing a .git directory should not throw an EPERM.
// Refs: https://github.com/isaacs/rimraf/issues/21.
if (isGitPresent) {
const gitDirectory = nextDirPath();
gitInit(gitDirectory);
fs.rm(gitDirectory, common.mustNotMutateObjectDeep({ recursive: true }), common.mustSucceed(() => {
assert.strictEqual(fs.existsSync(gitDirectory), false);
}));
}
// Test the synchronous version.
{
const dir = nextDirPath();
makeNonEmptyDirectory(4, 10, 2, dir, true);
// Removal should fail without the recursive option set to true.
assert.throws(() => {
fs.rmSync(dir);
}, { syscall: 'rm' });
assert.throws(() => {
fs.rmSync(dir, common.mustNotMutateObjectDeep({ recursive: false }));
}, { syscall: 'rm' });
// Should fail if target does not exist
assert.throws(() => {
fs.rmSync(path.join(tmpdir.path, 'noexist.txt'), common.mustNotMutateObjectDeep({ recursive: true }));
}, {
code: 'ENOENT',
name: 'Error',
message: /^ENOENT: no such file or directory, stat/
});
// Should delete a file
const filePath = path.join(tmpdir.path, 'rm-file.txt');
fs.writeFileSync(filePath, '');
try {
fs.rmSync(filePath, common.mustNotMutateObjectDeep({ recursive: true }));
} finally {
fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true }));
}
// Should accept URL
const fileURL = pathToFileURL(path.join(tmpdir.path, 'rm-file.txt'));
fs.writeFileSync(fileURL, '');
try {
fs.rmSync(fileURL, common.mustNotMutateObjectDeep({ recursive: true }));
} finally {
fs.rmSync(fileURL, common.mustNotMutateObjectDeep({ force: true }));
}
// Recursive removal should succeed.
fs.rmSync(dir, { recursive: true });
// Attempted removal should fail now because the directory is gone.
assert.throws(() => fs.rmSync(dir), { syscall: 'stat' });
}
// Removing a .git directory should not throw an EPERM.
// Refs: https://github.com/isaacs/rimraf/issues/21.
if (isGitPresent) {
const gitDirectory = nextDirPath();
gitInit(gitDirectory);
fs.rmSync(gitDirectory, common.mustNotMutateObjectDeep({ recursive: true }));
assert.strictEqual(fs.existsSync(gitDirectory), false);
}
// Test the Promises based version.
(async () => {
const dir = nextDirPath();
makeNonEmptyDirectory(4, 10, 2, dir, true);
// Removal should fail without the recursive option set to true.
await assert.rejects(fs.promises.rm(dir), { syscall: 'rm' });
await assert.rejects(fs.promises.rm(dir, common.mustNotMutateObjectDeep({ recursive: false })), {
syscall: 'rm'
});
// Recursive removal should succeed.
await fs.promises.rm(dir, common.mustNotMutateObjectDeep({ recursive: true }));
// Attempted removal should fail now because the directory is gone.
await assert.rejects(fs.promises.rm(dir), { syscall: 'stat' });
// Should fail if target does not exist
await assert.rejects(fs.promises.rm(
path.join(tmpdir.path, 'noexist.txt'),
{ recursive: true }
), {
code: 'ENOENT',
name: 'Error',
message: /^ENOENT: no such file or directory, stat/
});
// Should not fail if target does not exist and force option is true
await fs.promises.rm(path.join(tmpdir.path, 'noexist.txt'), common.mustNotMutateObjectDeep({ force: true }));
// Should delete file
const filePath = path.join(tmpdir.path, 'rm-promises-file.txt');
fs.writeFileSync(filePath, '');
try {
await fs.promises.rm(filePath, common.mustNotMutateObjectDeep({ recursive: true }));
} finally {
fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true }));
}
// Should accept URL
const fileURL = pathToFileURL(path.join(tmpdir.path, 'rm-promises-file.txt'));
fs.writeFileSync(fileURL, '');
try {
await fs.promises.rm(fileURL, common.mustNotMutateObjectDeep({ recursive: true }));
} finally {
fs.rmSync(fileURL, common.mustNotMutateObjectDeep({ force: true }));
}
})().then(common.mustCall());
// Removing a .git directory should not throw an EPERM.
// Refs: https://github.com/isaacs/rimraf/issues/21.
if (isGitPresent) {
(async () => {
const gitDirectory = nextDirPath();
gitInit(gitDirectory);
await fs.promises.rm(gitDirectory, common.mustNotMutateObjectDeep({ recursive: true }));
assert.strictEqual(fs.existsSync(gitDirectory), false);
})().then(common.mustCall());
}
// Test input validation.
{
const dir = nextDirPath();
makeNonEmptyDirectory(4, 10, 2, dir, true);
const filePath = (path.join(tmpdir.path, 'rm-args-file.txt'));
fs.writeFileSync(filePath, '');
const defaults = {
retryDelay: 100,
maxRetries: 0,
recursive: false,
force: false
};
const modified = {
retryDelay: 953,
maxRetries: 5,
recursive: true,
force: false
};
assert.deepStrictEqual(validateRmOptionsSync(filePath), defaults);
assert.deepStrictEqual(validateRmOptionsSync(filePath, {}), defaults);
assert.deepStrictEqual(validateRmOptionsSync(filePath, modified), modified);
assert.deepStrictEqual(validateRmOptionsSync(filePath, {
maxRetries: 99
}), {
retryDelay: 100,
maxRetries: 99,
recursive: false,
force: false
});
[null, 'foo', 5, NaN].forEach((bad) => {
assert.throws(() => {
validateRmOptionsSync(filePath, bad);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /^The "options" argument must be of type object\./
});
});
[undefined, null, 'foo', Infinity, function() {}].forEach((bad) => {
assert.throws(() => {
validateRmOptionsSync(filePath, { recursive: bad });
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /^The "options\.recursive" property must be of type boolean\./
});
});
[undefined, null, 'foo', Infinity, function() {}].forEach((bad) => {
assert.throws(() => {
validateRmOptionsSync(filePath, { force: bad });
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /^The "options\.force" property must be of type boolean\./
});
});
assert.throws(() => {
validateRmOptionsSync(filePath, { retryDelay: -1 });
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /^The value of "options\.retryDelay" is out of range\./
});
assert.throws(() => {
validateRmOptionsSync(filePath, { maxRetries: -1 });
}, {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /^The value of "options\.maxRetries" is out of range\./
});
}
{
// IBMi has a different access permission mechanism
// This test should not be run as `root`
if (!common.isIBMi && (common.isWindows || process.getuid() !== 0)) {
function makeDirectoryReadOnly(dir, mode) {
let accessErrorCode = 'EACCES';
if (common.isWindows) {
accessErrorCode = 'EPERM';
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(DE,DC)"`);
} else {
fs.chmodSync(dir, mode);
}
return accessErrorCode;
}
function makeDirectoryWritable(dir) {
if (fs.existsSync(dir)) {
if (common.isWindows) {
execSync(`icacls ${dir} /remove:d "everyone"`);
} else {
fs.chmodSync(dir, 0o777);
}
}
}
{
// Check that deleting a file that cannot be accessed using rmsync throws
// https://github.com/nodejs/node/issues/38683
const dirname = nextDirPath();
const filePath = path.join(dirname, 'text.txt');
try {
fs.mkdirSync(dirname, common.mustNotMutateObjectDeep({ recursive: true }));
fs.writeFileSync(filePath, 'hello');
const code = makeDirectoryReadOnly(dirname, 0o444);
assert.throws(() => {
fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true }));
}, {
code,
name: 'Error',
});
} finally {
makeDirectoryWritable(dirname);
}
}
{
// Check endless recursion.
// https://github.com/nodejs/node/issues/34580
const dirname = nextDirPath();
fs.mkdirSync(dirname, common.mustNotMutateObjectDeep({ recursive: true }));
const root = fs.mkdtempSync(path.join(dirname, 'fs-'));
const middle = path.join(root, 'middle');
fs.mkdirSync(middle);
fs.mkdirSync(path.join(middle, 'leaf')); // Make `middle` non-empty
try {
const code = makeDirectoryReadOnly(middle, 0o555);
try {
assert.throws(() => {
fs.rmSync(root, common.mustNotMutateObjectDeep({ recursive: true }));
}, {
code,
name: 'Error',
});
} catch (err) {
// Only fail the test if the folder was not deleted.
// as in some cases rmSync succesfully deletes read-only folders.
if (fs.existsSync(root)) {
throw err;
}
}
} finally {
makeDirectoryWritable(middle);
}
}
}
}

View file

@ -1,105 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
if (common.isIBMi)
common.skip('IBMi does not support `fs.watch()`');
// Tests if `filename` is provided to watcher on supported platforms
const fs = require('fs');
const assert = require('assert');
const { join } = require('path');
class WatchTestCase {
constructor(shouldInclude, dirName, fileName, field) {
this.dirName = dirName;
this.fileName = fileName;
this.field = field;
this.shouldSkip = !shouldInclude;
}
get dirPath() { return join(tmpdir.path, this.dirName); }
get filePath() { return join(this.dirPath, this.fileName); }
}
const cases = [
// Watch on a file should callback with a filename on supported systems
new WatchTestCase(
common.isLinux || common.isOSX || common.isWindows || common.isAIX,
'watch1',
'foo',
'filePath'
),
// Watch on a directory should callback with a filename on supported systems
new WatchTestCase(
common.isLinux || common.isOSX || common.isWindows,
'watch2',
'bar',
'dirPath'
),
];
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
for (const testCase of cases) {
if (testCase.shouldSkip) continue;
fs.mkdirSync(testCase.dirPath);
// Long content so it's actually flushed.
const content1 = Date.now() + testCase.fileName.toLowerCase().repeat(1e4);
fs.writeFileSync(testCase.filePath, content1);
let interval;
const pathToWatch = testCase[testCase.field];
const watcher = fs.watch(pathToWatch);
watcher.on('error', (err) => {
if (interval) {
clearInterval(interval);
interval = null;
}
assert.fail(err);
});
watcher.on('close', common.mustCall(() => {
watcher.close(); // Closing a closed watcher should be a noop
}));
watcher.on('change', common.mustCall(function(eventType, argFilename) {
if (interval) {
clearInterval(interval);
interval = null;
}
if (common.isOSX)
assert.strictEqual(['rename', 'change'].includes(eventType), true);
else
assert.strictEqual(eventType, 'change');
assert.strictEqual(argFilename, testCase.fileName);
watcher.close();
// We document that watchers cannot be used anymore when it's closed,
// here we turn the methods into noops instead of throwing
watcher.close(); // Closing a closed watcher should be a noop
}));
// Long content so it's actually flushed. toUpperCase so there's real change.
const content2 = Date.now() + testCase.fileName.toUpperCase().repeat(1e4);
interval = setInterval(() => {
fs.writeFileSync(testCase.filePath, '');
fs.writeFileSync(testCase.filePath, content2);
}, 100);
}
[false, 1, {}, [], null, undefined].forEach((input) => {
assert.throws(
() => fs.watch(input, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
}
);
});

View file

@ -1,114 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const expected = 'ümlaut. Лорем 運務ホソモ指及 आपको करने विकास 紙読決多密所 أضف';
const getFileName = (i) => path.join(tmpdir.path, `writev_${i}.txt`);
/**
* Testing with a array of buffers input
*/
// fs.writev with array of buffers with all parameters
{
const filename = getFileName(1);
const fd = fs.openSync(filename, 'w');
const buffer = Buffer.from(expected);
const bufferArr = [buffer, buffer];
const done = common.mustSucceed((written, buffers) => {
assert.deepStrictEqual(bufferArr, buffers);
const expectedLength = bufferArr.length * buffer.byteLength;
assert.deepStrictEqual(written, expectedLength);
fs.closeSync(fd);
assert(Buffer.concat(bufferArr).equals(fs.readFileSync(filename)));
});
fs.writev(fd, bufferArr, null, done);
}
// fs.writev with array of buffers without position
{
const filename = getFileName(2);
const fd = fs.openSync(filename, 'w');
const buffer = Buffer.from(expected);
const bufferArr = [buffer, buffer];
const done = common.mustSucceed((written, buffers) => {
assert.deepStrictEqual(bufferArr, buffers);
const expectedLength = bufferArr.length * buffer.byteLength;
assert.deepStrictEqual(written, expectedLength);
fs.closeSync(fd);
assert(Buffer.concat(bufferArr).equals(fs.readFileSync(filename)));
});
fs.writev(fd, bufferArr, done);
}
// fs.writev with empty array of buffers
{
const filename = getFileName(3);
const fd = fs.openSync(filename, 'w');
const bufferArr = [];
let afterSyncCall = false;
const done = common.mustSucceed((written, buffers) => {
assert.strictEqual(buffers.length, 0);
assert.strictEqual(written, 0);
assert(afterSyncCall);
fs.closeSync(fd);
});
fs.writev(fd, bufferArr, done);
afterSyncCall = true;
}
/**
* Testing with wrong input types
*/
{
const filename = getFileName(4);
const fd = fs.openSync(filename, 'w');
[false, 'test', {}, [{}], ['sdf'], null, undefined].forEach((i) => {
assert.throws(
() => fs.writev(fd, i, null, common.mustNotCall()), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
}
);
});
fs.closeSync(fd);
}
// fs.writev with wrong fd types
[false, 'test', {}, [{}], null, undefined].forEach((i) => {
assert.throws(
() => fs.writev(i, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
}
);
});

View file

@ -1,24 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const OutgoingMessage = http.OutgoingMessage;
{
const msg = new OutgoingMessage();
assert.strictEqual(msg.destroyed, false);
msg.destroy();
assert.strictEqual(msg.destroyed, true);
msg.write('asd', common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_STREAM_DESTROYED');
}));
msg.on('error', common.mustNotCall());
}

View file

@ -1,47 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
// Verify that after calling end() on an `OutgoingMessage` (or a type that
// inherits from `OutgoingMessage`), its `writable` property is not set to false
const server = http.createServer(common.mustCall(function(req, res) {
assert.strictEqual(res.writable, true);
assert.strictEqual(res.finished, false);
assert.strictEqual(res.writableEnded, false);
res.end();
// res.writable is set to false after it has finished sending
// Ref: https://github.com/nodejs/node/issues/15029
assert.strictEqual(res.writable, true);
assert.strictEqual(res.finished, true);
assert.strictEqual(res.writableEnded, true);
server.close();
}));
server.listen(0);
server.on('listening', common.mustCall(function() {
const clientRequest = http.request({
port: server.address().port,
method: 'GET',
path: '/'
});
assert.strictEqual(clientRequest.writable, true);
clientRequest.end();
// Writable is still true when close
// THIS IS LEGACY, we cannot change it
// unless we break error detection
assert.strictEqual(clientRequest.writable, true);
}));

View file

@ -1,58 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer(common.mustCall((s) => {
console.error('SERVER: got connection');
s.end();
}));
server.listen(0, common.mustCall(() => {
const c = net.createConnection(server.address().port);
c.on('close', common.mustCall(() => {
/* eslint-disable no-unused-expressions */
console.error('connection closed');
assert.strictEqual(c._handle, null);
// Calling functions / accessing properties of a closed socket should not
// throw.
c.setNoDelay();
c.setKeepAlive();
c.bufferSize;
c.pause();
c.resume();
c.address();
c.remoteAddress;
c.remotePort;
server.close();
/* eslint-enable no-unused-expressions */
}));
}));

View file

@ -1,54 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
{
const server = net.createServer(common.mustCall((socket) => {
socket.end(Buffer.alloc(1024));
})).listen(0, common.mustCall(() => {
const socket = net.connect(server.address().port);
assert.strictEqual(socket.allowHalfOpen, false);
socket.resume();
socket.on('end', common.mustCall(() => {
process.nextTick(() => {
// Ensure socket is not destroyed straight away
// without proper shutdown.
assert(!socket.destroyed);
server.close();
});
}));
socket.on('finish', common.mustCall(() => {
assert(!socket.destroyed);
}));
socket.on('close', common.mustCall());
}));
}
{
const server = net.createServer(common.mustCall((socket) => {
socket.end(Buffer.alloc(1024));
})).listen(0, common.mustCall(() => {
const socket = net.connect(server.address().port);
assert.strictEqual(socket.allowHalfOpen, false);
socket.resume();
socket.on('end', common.mustCall(() => {
assert(!socket.destroyed);
}));
socket.end('asd');
socket.on('finish', common.mustCall(() => {
assert(!socket.destroyed);
}));
socket.on('close', common.mustCall(() => {
server.close();
}));
}));
}

View file

@ -1,19 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer(common.mustNotCall());
server.listen(1, '1.1.1.1', common.mustNotCall());
server.on('error', common.mustCall(function(e) {
assert.strictEqual(e.address, '1.1.1.1');
assert.strictEqual(e.port, 1);
assert.strictEqual(e.syscall, 'listen');
}));

View file

@ -1,43 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server1 = net.createServer(common.mustNotCall());
server1.listen(0, '127.0.0.1', common.mustCall(function() {
const server2 = net.createServer(common.mustNotCall());
server2.listen(this.address().port, '127.0.0.1', common.mustNotCall());
server2.on('error', common.mustCall(function(e) {
assert.strictEqual(e.code, 'EADDRINUSE');
server1.close();
}));
}));

View file

@ -1,59 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const iter = 10;
const server = net.createServer(function(socket) {
socket.on('readable', function() {
socket.read();
});
socket.on('end', function() {
server.close();
});
});
server.listen(0, common.mustCall(function() {
const client = net.connect(this.address().port);
client.on('finish', common.mustCall(() => {
assert.strictEqual(client.bufferSize, 0);
}));
for (let i = 1; i < iter; i++) {
client.write('a');
assert.strictEqual(client.bufferSize, i);
}
client.end();
}));

View file

@ -1,74 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
// Regression test for https://github.com/nodejs/node/issues/19562:
// Writing to a socket first tries to push through as much data as possible
// without blocking synchronously, and, if that is not enough, queues more
// data up for asynchronous writing.
// Check that `bytesWritten` accounts for both parts of a write.
const N = 10000000;
{
// Variant 1: Write a Buffer.
const server = net.createServer(common.mustCall((socket) => {
socket.end(Buffer.alloc(N), common.mustCall(() => {
assert.strictEqual(socket.bytesWritten, N);
}));
assert.strictEqual(socket.bytesWritten, N);
})).listen(0, common.mustCall(() => {
const client = net.connect(server.address().port);
client.resume();
client.on('close', common.mustCall(() => {
assert.strictEqual(client.bytesRead, N);
server.close();
}));
}));
}
{
// Variant 2: Write a string.
const server = net.createServer(common.mustCall((socket) => {
socket.end('a'.repeat(N), common.mustCall(() => {
assert.strictEqual(socket.bytesWritten, N);
}));
assert.strictEqual(socket.bytesWritten, N);
})).listen(0, common.mustCall(() => {
const client = net.connect(server.address().port);
client.resume();
client.on('close', common.mustCall(() => {
assert.strictEqual(client.bytesRead, N);
server.close();
}));
}));
}
{
// Variant 2: writev() with mixed data.
const server = net.createServer(common.mustCall((socket) => {
socket.cork();
socket.write('a'.repeat(N));
assert.strictEqual(socket.bytesWritten, N);
socket.write(Buffer.alloc(N));
assert.strictEqual(socket.bytesWritten, 2 * N);
socket.end('', common.mustCall(() => {
assert.strictEqual(socket.bytesWritten, 2 * N);
}));
socket.uncork();
})).listen(0, common.mustCall(() => {
const client = net.connect(server.address().port);
client.resume();
client.on('close', common.mustCall(() => {
assert.strictEqual(client.bytesRead, 2 * N);
server.close();
}));
}));
}

View file

@ -1,64 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
// Ref: https://github.com/nodejs/node-v0.x-archive/issues/481
const net = require('net');
const server = net.createServer(common.mustCall(function(stream) {
stream.setTimeout(100);
stream.resume();
stream.once('timeout', common.mustCall(function() {
console.log('timeout');
// Try to reset the timeout.
stream.write('WHAT.');
}));
stream.on('end', common.mustCall(function() {
console.log('server side end');
stream.end();
}));
}));
server.listen(0, common.mustCall(function() {
const c = net.createConnection(this.address().port);
c.on('data', function() {
c.end();
});
c.on('end', function() {
console.log('client side end');
server.close();
});
}));

View file

@ -1,46 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
// This test checks that calling `net.connect` internally calls
// `Socket.prototype.connect`.
//
// This is important for people who monkey-patch `Socket.prototype.connect`
// since it's not possible to monkey-patch `net.connect` directly (as the core
// `connect` function is called internally in Node instead of calling the
// `exports.connect` function).
//
// Monkey-patching of `Socket.prototype.connect` is done by - among others -
// most APM vendors, the async-listener module and the
// continuation-local-storage module.
//
// Related:
// - https://github.com/nodejs/node/pull/12342
// - https://github.com/nodejs/node/pull/12852
const net = require('net');
const Socket = net.Socket;
// Monkey patch Socket.prototype.connect to check that it's called.
const orig = Socket.prototype.connect;
Socket.prototype.connect = common.mustCall(function() {
return orig.apply(this, arguments);
});
const server = net.createServer();
server.listen(common.mustCall(function() {
const port = server.address().port;
const client = net.connect({ port }, common.mustCall(function() {
client.end();
}));
client.on('end', common.mustCall(function() {
server.close();
}));
}));

View file

@ -1,74 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// Test that the family option of net.connect is honored.
'use strict';
const common = require('../common');
if (!common.hasIPv6)
common.skip('no IPv6 support');
const assert = require('assert');
const net = require('net');
const hostAddrIPv6 = '::1';
const HOSTNAME = 'dummy';
const server = net.createServer({ allowHalfOpen: true }, (socket) => {
socket.resume();
socket.on('end', common.mustCall());
socket.end();
});
function tryConnect() {
const connectOpt = {
host: HOSTNAME,
port: server.address().port,
family: 6,
allowHalfOpen: true,
lookup: common.mustCall((addr, opt, cb) => {
assert.strictEqual(addr, HOSTNAME);
assert.strictEqual(opt.family, 6);
cb(null, hostAddrIPv6, opt.family);
})
};
// No `mustCall`, since test could skip, and it's the only path to `close`.
const client = net.connect(connectOpt, () => {
client.resume();
client.on('end', () => {
// Wait for next uv tick and make sure the socket stream is writable.
setTimeout(function() {
assert(client.writable);
client.end();
}, 10);
});
client.on('close', () => server.close());
});
}
server.listen(0, hostAddrIPv6, tryConnect);

View file

@ -1,237 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dns = require('dns');
const net = require('net');
// Test wrong type of ports
{
const portTypeError = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
};
syncFailToConnect(true, portTypeError);
syncFailToConnect(false, portTypeError);
syncFailToConnect([], portTypeError, true);
syncFailToConnect({}, portTypeError, true);
syncFailToConnect(null, portTypeError);
}
// Test out of range ports
{
const portRangeError = {
code: 'ERR_SOCKET_BAD_PORT',
name: 'RangeError'
};
syncFailToConnect('', portRangeError);
syncFailToConnect(' ', portRangeError);
syncFailToConnect('0x', portRangeError, true);
syncFailToConnect('-0x1', portRangeError, true);
syncFailToConnect(NaN, portRangeError);
syncFailToConnect(Infinity, portRangeError);
syncFailToConnect(-1, portRangeError);
syncFailToConnect(65536, portRangeError);
}
// Test invalid hints
{
// connect({hint}, cb) and connect({hint})
const hints = (dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL) + 42;
const hintOptBlocks = doConnect([{ port: 42, hints }],
() => common.mustNotCall());
for (const fn of hintOptBlocks) {
assert.throws(fn, {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: /The argument 'hints' is invalid\. Received \d+/
});
}
}
// Test valid combinations of connect(port) and connect(port, host)
{
const expectedConnections = 72;
let serverConnected = 0;
const server = net.createServer(common.mustCall((socket) => {
socket.end('ok');
if (++serverConnected === expectedConnections) {
server.close();
}
}, expectedConnections));
server.listen(0, common.localhostIPv4, common.mustCall(() => {
const port = server.address().port;
// Total connections = 3 * 4(canConnect) * 6(doConnect) = 72
canConnect(port);
canConnect(String(port));
canConnect(`0x${port.toString(16)}`);
}));
// Try connecting to random ports, but do so once the server is closed
server.on('close', () => {
asyncFailToConnect(0);
});
}
function doConnect(args, getCb) {
return [
function createConnectionWithCb() {
return net.createConnection.apply(net, args.concat(getCb()))
.resume();
},
function createConnectionWithoutCb() {
return net.createConnection.apply(net, args)
.on('connect', getCb())
.resume();
},
function connectWithCb() {
return net.connect.apply(net, args.concat(getCb()))
.resume();
},
function connectWithoutCb() {
return net.connect.apply(net, args)
.on('connect', getCb())
.resume();
},
function socketConnectWithCb() {
const socket = new net.Socket();
return socket.connect.apply(socket, args.concat(getCb()))
.resume();
},
function socketConnectWithoutCb() {
const socket = new net.Socket();
return socket.connect.apply(socket, args)
.on('connect', getCb())
.resume();
},
];
}
function syncFailToConnect(port, assertErr, optOnly) {
const family = 4;
if (!optOnly) {
// connect(port, cb) and connect(port)
const portArgFunctions = doConnect([{ port, family }],
() => common.mustNotCall());
for (const fn of portArgFunctions) {
assert.throws(fn, assertErr, `${fn.name}(${port})`);
}
// connect(port, host, cb) and connect(port, host)
const portHostArgFunctions = doConnect([{ port,
host: 'localhost',
family }],
() => common.mustNotCall());
for (const fn of portHostArgFunctions) {
assert.throws(fn, assertErr, `${fn.name}(${port}, 'localhost')`);
}
}
// connect({port}, cb) and connect({port})
const portOptFunctions = doConnect([{ port, family }],
() => common.mustNotCall());
for (const fn of portOptFunctions) {
assert.throws(fn, assertErr, `${fn.name}({port: ${port}})`);
}
// connect({port, host}, cb) and connect({port, host})
const portHostOptFunctions = doConnect([{ port: port,
host: 'localhost',
family: family }],
() => common.mustNotCall());
for (const fn of portHostOptFunctions) {
assert.throws(fn,
assertErr,
`${fn.name}({port: ${port}, host: 'localhost'})`);
}
}
function canConnect(port) {
const noop = () => common.mustCall();
const family = 4;
// connect(port, cb) and connect(port)
const portArgFunctions = doConnect([{ port, family }], noop);
for (const fn of portArgFunctions) {
fn();
}
// connect(port, host, cb) and connect(port, host)
const portHostArgFunctions = doConnect([{ port, host: 'localhost', family }],
noop);
for (const fn of portHostArgFunctions) {
fn();
}
// connect({port}, cb) and connect({port})
const portOptFunctions = doConnect([{ port, family }], noop);
for (const fn of portOptFunctions) {
fn();
}
// connect({port, host}, cb) and connect({port, host})
const portHostOptFns = doConnect([{ port, host: 'localhost', family }],
noop);
for (const fn of portHostOptFns) {
fn();
}
}
function asyncFailToConnect(port) {
const onError = () => common.mustCall((err) => {
const regexp = /^Error: connect E\w+.+$/;
assert.match(String(err), regexp);
});
const dont = () => common.mustNotCall();
const family = 4;
// connect(port, cb) and connect(port)
const portArgFunctions = doConnect([{ port, family }], dont);
for (const fn of portArgFunctions) {
fn().on('error', onError());
}
// connect({port}, cb) and connect({port})
const portOptFunctions = doConnect([{ port, family }], dont);
for (const fn of portOptFunctions) {
fn().on('error', onError());
}
// connect({port, host}, cb) and connect({port, host})
const portHostOptFns = doConnect([{ port, host: 'localhost', family }],
dont);
for (const fn of portHostOptFns) {
fn().on('error', onError());
}
}

View file

@ -1,61 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
function check(addressType, cb) {
const server = net.createServer(function(client) {
client.end();
server.close();
cb && cb();
});
const address = addressType === 4 ? common.localhostIPv4 : '::1';
server.listen(0, address, common.mustCall(function() {
net.connect({
port: this.address().port,
host: 'localhost',
family: addressType,
lookup: lookup
}).on('lookup', common.mustCall(function(err, ip, type) {
assert.strictEqual(err, null);
assert.strictEqual(address, ip);
assert.strictEqual(type, addressType);
}));
}));
function lookup(host, dnsopts, cb) {
dnsopts.family = addressType;
if (addressType === 4) {
process.nextTick(function() {
cb(null, common.localhostIPv4, 4);
});
} else {
process.nextTick(function() {
cb(null, '::1', 6);
});
}
}
}
check(4, function() {
common.hasIPv6 && check(6);
});
// Verify that bad lookup() IPs are handled.
{
net.connect({
host: 'localhost',
port: 80,
lookup(host, dnsopts, cb) {
cb(null, undefined, 4);
}
}).on('error', common.expectsError({ code: 'ERR_INVALID_IP_ADDRESS' }));
}

View file

@ -1,26 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const net = require('net');
function check(addressType) {
const server = net.createServer(function(client) {
client.end();
server.close();
});
const address = addressType === 4 ? '127.0.0.1' : '::1';
server.listen(0, address, function() {
net.connect(this.address().port, address)
.on('lookup', common.mustNotCall());
});
}
check(4);
common.hasIPv6 && check(6);

View file

@ -1,47 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer(function(client) {
client.end();
server.close();
});
server.listen(0, common.mustCall(function() {
net.connect(this.address().port, 'localhost')
.on('lookup', common.mustCall(function(err, ip, type, host) {
assert.strictEqual(err, null);
assert.match(ip, /^(127\.0\.0\.1|::1)$/);
assert.match(type.toString(), /^(4|6)$/);
assert.strictEqual(host, 'localhost');
}));
}));

View file

@ -1,44 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server1 = net.createServer(function(socket) {
});
const server2 = net.createServer(function(socket) {
});
server1.listen(0, common.mustCall(function() {
server2.on('error', function(error) {
assert.strictEqual(error.message.includes('EADDRINUSE'), true);
server1.close();
});
server2.listen(this.address().port);
}));

View file

@ -1,33 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const net = require('net');
const assert = require('assert');
const server = net.createServer();
server.on('connection', common.mustCall());
// Ensure that the socket is not destroyed when the 'end' event is emitted.
server.listen(common.mustCall(function() {
const socket = net.createConnection({
port: server.address().port
});
socket.on('connect', common.mustCall(function() {
socket.on('end', common.mustCall(function() {
assert.strictEqual(socket.destroyed, false);
server.close();
}));
socket.end();
}));
}));

View file

@ -1,29 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
// Just test that destroying stdin doesn't mess up listening on a server.
// This is a regression test for
// https://github.com/nodejs/node-v0.x-archive/issues/746.
const common = require('../common');
const net = require('net');
process.stdin.destroy();
const server = net.createServer(common.mustCall((socket) => {
console.log('accepted...');
socket.end(common.mustCall(() => { console.log('finished...'); }));
server.close(common.mustCall(() => { console.log('closed'); }));
}));
server.listen(0, common.mustCall(() => {
console.log('listening...');
net.createConnection(server.address().port);
}));

View file

@ -1,36 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const net = require('net');
const server = net.createServer(function(socket) {
});
server.listen(1, '1.1.1.1', common.mustNotCall()); // EACCES or EADDRNOTAVAIL
server.on('error', common.mustCall());

View file

@ -1,50 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer(common.mustCall(function(socket) {
assert.strictEqual(socket.localAddress, common.localhostIPv4);
assert.strictEqual(socket.localPort, this.address().port);
assert.strictEqual(socket.localFamily, this.address().family);
socket.on('end', function() {
server.close();
});
socket.resume();
}));
server.listen(0, common.localhostIPv4, function() {
const client = net.createConnection(this.address()
.port, common.localhostIPv4);
client.on('connect', function() {
client.end();
});
});

View file

@ -1,102 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
let connections = 0;
let dataEvents = 0;
let conn;
// Server
const server = net.createServer(function(conn) {
connections++;
conn.end('This was the year he fell to pieces.');
if (connections === 5)
server.close();
});
server.listen(0, function() {
// Client 1
conn = net.createConnection(this.address().port, 'localhost');
conn.resume();
conn.on('data', onDataOk);
// Client 2
conn = net.createConnection(this.address().port, 'localhost');
conn.pause();
conn.resume();
conn.on('data', onDataOk);
// Client 3
conn = net.createConnection(this.address().port, 'localhost');
conn.pause();
conn.on('data', common.mustNotCall());
scheduleTearDown(conn);
// Client 4
conn = net.createConnection(this.address().port, 'localhost');
conn.resume();
conn.pause();
conn.resume();
conn.on('data', onDataOk);
// Client 5
conn = net.createConnection(this.address().port, 'localhost');
conn.resume();
conn.resume();
conn.pause();
conn.on('data', common.mustNotCall());
scheduleTearDown(conn);
function onDataOk() {
dataEvents++;
}
function scheduleTearDown(conn) {
setTimeout(function() {
conn.removeAllListeners('data');
conn.resume();
}, 100);
}
});
// Exit sanity checks
process.on('exit', function() {
assert.strictEqual(connections, 5);
assert.strictEqual(dataEvents, 3);
});

View file

@ -1,48 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const net = require('net');
const { internalBinding } = require('internal/test/binding');
const TCPWrap = internalBinding('tcp_wrap').TCP;
const echoServer = net.createServer((conn) => {
conn.end();
});
const ref = TCPWrap.prototype.ref;
const unref = TCPWrap.prototype.unref;
let refCount = 0;
TCPWrap.prototype.ref = function() {
ref.call(this);
refCount++;
assert.strictEqual(refCount, 0);
};
TCPWrap.prototype.unref = function() {
unref.call(this);
refCount--;
assert.strictEqual(refCount, -1);
};
echoServer.listen(0);
echoServer.on('listening', function() {
const sock = new net.Socket();
sock.unref();
sock.ref();
sock.connect(this.address().port);
sock.on('end', () => {
assert.strictEqual(refCount, 0);
echoServer.close();
});
});

View file

@ -1,91 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
let conns_closed = 0;
const remoteAddrCandidates = [ common.localhostIPv4,
'::1',
'::ffff:127.0.0.1' ];
const remoteFamilyCandidates = ['IPv4', 'IPv6'];
const server = net.createServer(common.mustCall(function(socket) {
assert.ok(remoteAddrCandidates.includes(socket.remoteAddress),
`Invalid remoteAddress: ${socket.remoteAddress}`);
assert.ok(remoteFamilyCandidates.includes(socket.remoteFamily),
`Invalid remoteFamily: ${socket.remoteFamily}`);
assert.ok(socket.remotePort);
assert.notStrictEqual(socket.remotePort, this.address().port);
socket.on('end', function() {
if (++conns_closed === 2) server.close();
});
socket.on('close', function() {
assert.ok(remoteAddrCandidates.includes(socket.remoteAddress));
assert.ok(remoteFamilyCandidates.includes(socket.remoteFamily));
});
socket.resume();
}, 2));
server.listen(0, function() {
const client = net.createConnection(this.address().port, '127.0.0.1');
const client2 = net.createConnection(this.address().port);
assert.strictEqual(client.remoteAddress, undefined);
assert.strictEqual(client.remoteFamily, undefined);
assert.strictEqual(client.remotePort, undefined);
assert.strictEqual(client2.remoteAddress, undefined);
assert.strictEqual(client2.remoteFamily, undefined);
assert.strictEqual(client2.remotePort, undefined);
client.on('connect', function() {
assert.ok(remoteAddrCandidates.includes(client.remoteAddress));
assert.ok(remoteFamilyCandidates.includes(client.remoteFamily));
assert.strictEqual(client.remotePort, server.address().port);
client.end();
});
client.on('close', function() {
assert.ok(remoteAddrCandidates.includes(client.remoteAddress));
assert.ok(remoteFamilyCandidates.includes(client.remoteFamily));
});
client2.on('connect', function() {
assert.ok(remoteAddrCandidates.includes(client2.remoteAddress));
assert.ok(remoteFamilyCandidates.includes(client2.remoteFamily));
assert.strictEqual(client2.remotePort, server.address().port);
client2.end();
});
client2.on('close', function() {
assert.ok(remoteAddrCandidates.includes(client2.remoteAddress));
assert.ok(remoteFamilyCandidates.includes(client2.remoteFamily));
});
});

View file

@ -1,34 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const events = require('events');
const { createServer, connect } = require('net');
events.captureRejections = true;
const server = createServer(common.mustCall(async (sock) => {
server.close();
const _err = new Error('kaboom');
sock.on('error', common.mustCall((err) => {
assert.strictEqual(err, _err);
}));
throw _err;
}));
server.listen(0, common.mustCall(() => {
const sock = connect(
server.address().port,
server.address().host
);
sock.on('close', common.mustCall());
}));

View file

@ -1,52 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const sockets = [];
const server = net.createServer(function(c) {
c.on('close', common.mustCall());
sockets.push(c);
if (sockets.length === 2) {
assert.strictEqual(server.close(), server);
sockets.forEach((c) => c.destroy());
}
});
server.on('close', common.mustCall());
assert.strictEqual(server, server.listen(0, () => {
net.createConnection(server.address().port);
net.createConnection(server.address().port);
}));

View file

@ -1,114 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
// This test creates 20 connections to a server and sets the server's
// maxConnections property to 10. The first 10 connections make it through
// and the last 10 connections are rejected.
const N = 20;
let closes = 0;
const waits = [];
const server = net.createServer(common.mustCall(function(connection) {
connection.write('hello');
waits.push(function() { connection.end(); });
}, N / 2));
server.listen(0, function() {
makeConnection(0);
});
server.maxConnections = N / 2;
function makeConnection(index) {
const c = net.createConnection(server.address().port);
let gotData = false;
c.on('connect', function() {
if (index + 1 < N) {
makeConnection(index + 1);
}
c.on('close', function() {
console.error(`closed ${index}`);
closes++;
if (closes < N / 2) {
assert.ok(
server.maxConnections <= index,
`${index} should not have been one of the first closed connections`
);
}
if (closes === N / 2) {
let cb;
console.error('calling wait callback.');
while ((cb = waits.shift()) !== undefined) {
cb();
}
server.close();
}
if (index < server.maxConnections) {
assert.strictEqual(gotData, true,
`${index} didn't get data, but should have`);
} else {
assert.strictEqual(gotData, false,
`${index} got data, but shouldn't have`);
}
});
});
c.on('end', function() { c.end(); });
c.on('data', function(b) {
gotData = true;
assert.ok(b.length > 0);
});
c.on('error', function(e) {
// Retry if SmartOS and ECONNREFUSED. See
// https://github.com/nodejs/node/issues/2663.
if (common.isSunOS && (e.code === 'ECONNREFUSED')) {
c.connect(server.address().port);
}
console.error(`error ${index}: ${e}`);
});
}
process.on('exit', function() {
assert.strictEqual(closes, N);
});

View file

@ -1,79 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const msg = 'test';
let stopped = true;
let server1Sock;
const server1ConnHandler = (socket) => {
socket.on('data', function(data) {
if (stopped) {
assert.fail('data event should not have happened yet');
}
assert.strictEqual(data.toString(), msg);
socket.end();
server1.close();
});
server1Sock = socket;
};
const server1 = net.createServer({ pauseOnConnect: true }, server1ConnHandler);
const server2ConnHandler = (socket) => {
socket.on('data', function(data) {
assert.strictEqual(data.toString(), msg);
socket.end();
server2.close();
assert.strictEqual(server1Sock.bytesRead, 0);
server1Sock.resume();
stopped = false;
});
};
const server2 = net.createServer({ pauseOnConnect: false }, server2ConnHandler);
server1.listen(0, function() {
const clientHandler = common.mustCall(function() {
server2.listen(0, function() {
net.createConnection({ port: this.address().port }).write(msg);
});
});
net.createConnection({ port: this.address().port }).write(msg, clientHandler);
});
process.on('exit', function() {
assert.strictEqual(stopped, false);
});

View file

@ -1,38 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer();
server.on('connection', (socket) => {
let endEmitted = false;
socket.once('readable', () => {
setTimeout(() => {
socket.read();
}, common.platformTimeout(100));
});
socket.on('end', () => {
endEmitted = true;
});
socket.on('close', () => {
assert(endEmitted);
server.close();
});
socket.end('foo');
});
server.listen(common.mustCall(() => {
const socket = net.createConnection(server.address().port, () => {
socket.end('foo');
});
}));

View file

@ -1,33 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
// This test ensures that socket.connect can be called without callback
// which is optional.
const net = require('net');
const server = net.createServer(common.mustCall(function(conn) {
conn.end();
server.close();
})).listen(0, common.mustCall(function() {
const client = new net.Socket();
client.on('connect', common.mustCall(function() {
client.end();
}));
const address = server.address();
if (!common.hasIPv6 && address.family === 'IPv6') {
// Necessary to pass CI running inside containers.
client.connect(address.port);
} else {
client.connect(address);
}
}));

View file

@ -1,28 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer((conn) => {
conn.end();
server.close();
}).listen(0, () => {
const client = net.connect(server.address().port, () => {
assert.strictEqual(client.connecting, false);
// Legacy getter
assert.strictEqual(client._connecting, false);
client.end();
});
assert.strictEqual(client.connecting, true);
// Legacy getter
assert.strictEqual(client._connecting, true);
});

View file

@ -1,31 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const net = require('net');
const assert = require('assert');
const server = net.createServer();
server.listen(0, common.mustCall(function() {
const port = server.address().port;
const conn = net.createConnection(port);
conn.on('connect', common.mustCall(function() {
// Test destroy returns this, even on multiple calls when it short-circuits.
assert.strictEqual(conn, conn.destroy().destroy());
conn.on('error', common.mustNotCall());
conn.write(Buffer.from('kaboom'), common.expectsError({
code: 'ERR_STREAM_DESTROYED',
message: 'Cannot call write after a stream was destroyed',
name: 'Error'
}));
server.close();
}));
}));

View file

@ -1,20 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const net = require('net');
const server = net.createServer();
server.listen(common.mustCall(() => {
const socket = net.createConnection(server.address().port);
socket.on('close', common.mustCall(() => server.close()));
socket.end();
}));

View file

@ -1,29 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const net = require('net');
const server = net.createServer((socket) => {
socket.resume();
}).unref();
server.listen(common.mustCall(() => {
const connect = (...args) => {
const socket = net.createConnection(server.address().port, () => {
socket.end(...args);
});
};
const cb = common.mustCall(() => {}, 3);
connect(cb);
connect('foo', cb);
connect('foo', 'utf8', cb);
}));

View file

@ -1,27 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
// This test ensures that socket.connect can be called without callback
// which is optional.
const net = require('net');
const server = net.createServer(common.mustCall(function(conn) {
conn.end();
server.close();
})).listen(0, 'localhost', common.mustCall(function() {
const client = new net.Socket();
client.on('ready', common.mustCall(function() {
client.end();
}));
client.connect(server.address());
}));

View file

@ -1,49 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
{
const server = net.createServer();
server.listen(common.mustCall(() => {
const port = server.address().port;
const client = net.connect({ port }, common.mustCall(() => {
client.on('error', common.mustCall((err) => {
server.close();
assert.strictEqual(err.constructor, Error);
assert.strictEqual(err.message, 'write EBADF');
}));
client._handle.close();
client.write('foo');
}));
}));
}
{
const server = net.createServer();
server.listen(common.mustCall(() => {
const port = server.address().port;
const client = net.connect({ port }, common.mustCall(() => {
client.on('error', common.expectsError({
code: 'ERR_SOCKET_CLOSED',
message: 'Socket is closed',
name: 'Error'
}));
server.close();
client._handle.close();
client._handle = null;
client.write('foo');
}));
}));
}

View file

@ -1,29 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const net = require('net');
const assert = require('assert');
const server = net.createServer().listen(0, connectToServer);
function connectToServer() {
const client = net.createConnection(this.address().port, () => {
client.on('error', common.mustNotCall());
assert.throws(() => {
client.write(1337);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
});
client.destroy();
})
.on('close', () => server.close());
}

View file

@ -1,40 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer(handle);
const N = 100;
const buf = Buffer.alloc(2, 'a');
server.listen(0, function() {
const conn = net.connect(this.address().port);
conn.on('connect', () => {
let res = true;
let i = 0;
for (; i < N && res; i++) {
conn.cork();
conn.write(buf);
res = conn.write(buf);
conn.uncork();
}
assert.strictEqual(i, N);
conn.end();
});
});
function handle(socket) {
socket.resume();
socket.on('error', common.mustNotCall())
.on('close', common.mustCall(() => server.close()));
}

View file

@ -1,22 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer(common.mustCall(function(s) {
server.close();
s.end();
})).listen(0, '127.0.0.1', common.mustCall(function() {
const socket = net.connect(this.address().port, '127.0.0.1');
socket.on('end', common.mustCall(() => {
assert.strictEqual(socket.writable, true);
socket.write('hello world');
}));
}));

View file

@ -1,39 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const { expectsError, mustCall } = common;
// This test ensures those errors caused by calling `net.Socket.write()`
// after sockets ending will be emitted in the next tick.
const server = net.createServer(mustCall((socket) => {
socket.end();
})).listen(() => {
const client = net.connect(server.address().port, () => {
let hasError = false;
client.on('error', mustCall((err) => {
hasError = true;
server.close();
}));
client.on('end', mustCall(() => {
const ret = client.write('hello', expectsError({
code: 'EPIPE',
message: 'This socket has been ended by the other party',
name: 'Error'
}));
assert.strictEqual(ret, false);
assert(!hasError, 'The error should be emitted in the next tick.');
}));
client.end();
});
});

View file

@ -1,41 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
// Flags: --expose-gc
// Note: This is a variant of test-net-write-fully-async-hex-string.js.
// This always worked, but it seemed appropriate to add a test that checks the
// behavior for Buffers, too.
const common = require('../common');
const net = require('net');
const data = Buffer.alloc(1000000);
const server = net.createServer(common.mustCall(function(conn) {
conn.resume();
})).listen(0, common.mustCall(function() {
const conn = net.createConnection(this.address().port, common.mustCall(() => {
let count = 0;
function writeLoop() {
if (count++ === 200) {
conn.destroy();
server.close();
return;
}
while (conn.write(Buffer.from(data)));
global.gc({ type: 'minor' });
// The buffer allocated above should still be alive.
}
conn.on('drain', writeLoop);
writeLoop();
}));
}));

View file

@ -1,39 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';
// Flags: --expose-gc
// Regression test for https://github.com/nodejs/node/issues/8251.
const common = require('../common');
const net = require('net');
const data = Buffer.alloc(1000000).toString('hex');
const server = net.createServer(common.mustCall(function(conn) {
conn.resume();
})).listen(0, common.mustCall(function() {
const conn = net.createConnection(this.address().port, common.mustCall(() => {
let count = 0;
function writeLoop() {
if (count++ === 20) {
conn.destroy();
server.close();
return;
}
while (conn.write(data, 'hex'));
global.gc({ type: 'minor' });
// The buffer allocated inside the .write() call should still be alive.
}
conn.on('drain', writeLoop);
writeLoop();
}));
}));

View file

@ -1,70 +0,0 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const SIZE = 2E5;
const N = 10;
let flushed = 0;
let received = 0;
const buf = Buffer.alloc(SIZE, 'a');
const server = net.createServer(function(socket) {
socket.setNoDelay();
socket.setTimeout(9999);
socket.on('timeout', function() {
assert.fail(`flushed: ${flushed}, received: ${received}/${SIZE * N}`);
});
for (let i = 0; i < N; ++i) {
socket.write(buf, function() {
++flushed;
if (flushed === N) {
socket.setTimeout(0);
}
});
}
socket.end();
}).listen(0, common.mustCall(function() {
const conn = net.connect(this.address().port);
conn.on('data', function(buf) {
received += buf.length;
conn.pause();
setTimeout(function() {
conn.resume();
}, 20);
});
conn.on('end', common.mustCall(function() {
server.close();
assert.strictEqual(received, SIZE * N);
}));
}));

Some files were not shown because too many files have changed in this diff Show more