Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test-net-server-bind #13273

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 0 additions & 86 deletions test/parallel/test-net-server-bind.js

This file was deleted.

64 changes: 64 additions & 0 deletions test/sequential/test-net-server-bind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');


// With only a callback, server should get a port assigned by the OS
{
const server = net.createServer(common.mustNotCall());

server.listen(common.mustCall(function() {
assert.ok(server.address().port > 100);
server.close();
}));
}

// No callback to listen(), assume we can bind in 100 ms
{
const server = net.createServer(common.mustNotCall());

server.listen(common.PORT);

setTimeout(function() {
const address = server.address();
assert.strictEqual(address.port, common.PORT);

if (address.family === 'IPv6')
assert.strictEqual(server._connectionKey, `6::::${address.port}`);
else
assert.strictEqual(server._connectionKey, `4:0.0.0.0:${address.port}`);

server.close();
}, 100);
}

// Callback to listen()
{
const server = net.createServer(common.mustNotCall());

server.listen(common.PORT + 1, common.mustCall(function() {
assert.strictEqual(server.address().port, common.PORT + 1);
server.close();
}));
}

// Backlog argument
{
const server = net.createServer(common.mustNotCall());

server.listen(common.PORT + 2, '0.0.0.0', 127, common.mustCall(function() {
assert.strictEqual(server.address().port, common.PORT + 2);
server.close();
}));
}

// Backlog argument without host argument
{
const server = net.createServer(common.mustNotCall());

server.listen(common.PORT + 3, 127, common.mustCall(function() {
assert.strictEqual(server.address().port, common.PORT + 3);
server.close();
}));
}