Compare commits

...

2 Commits

Author SHA1 Message Date
Meghan Denny
af4501ad60 Delete test-net-sync-cork.js 2025-02-26 18:57:13 -08:00
Meghan Denny
c0e946d706 node:net: new passing tests 2025-02-26 17:55:32 -08:00
4 changed files with 136 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
'use strict';
const common = require('../common');
if (!common.hasIPv6)
common.skip('no IPv6 support');
// This test ensures that dual-stack support is disabled when
// we specify the `ipv6Only` option in `net.Server.listen()`.
const assert = require('assert');
const net = require('net');
const host = '::';
const server = net.createServer();
server.listen({
host,
port: 0,
ipv6Only: true,
}, common.mustCall(() => {
const { port } = server.address();
const socket = net.connect({
host: '0.0.0.0',
port,
});
socket.on('connect', common.mustNotCall());
socket.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ECONNREFUSED');
server.close();
}));
}));

View File

@@ -0,0 +1,45 @@
// 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

@@ -0,0 +1,16 @@
'use strict';
require('../common');
const assert = require('assert');
const net = require('net');
assert.throws(() => net.createServer('path'),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
});
assert.throws(() => net.createServer(0),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
});

View File

@@ -0,0 +1,45 @@
// 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';
// This test binds to one port, then attempts to start a server on that
// port. It should be EADDRINUSE but be able to then bind to another port.
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server1 = net.Server();
const server2 = net.Server();
server2.on('error', common.mustCall(function(e) {
assert.strictEqual(e.code, 'EADDRINUSE');
server2.listen(0, common.mustCall(function() {
server1.close();
server2.close();
}));
}));
server1.listen(0, common.mustCall(function() {
// This should make server2 emit EADDRINUSE
server2.listen(this.address().port);
}));