Skip to content

Commit

Permalink
test: refactor test-net-server-bind
Browse files Browse the repository at this point in the history
* Use common.mustNotCall() and common.mustCall() as appropriate
* Use block scoping
* Move assertions out of `exit` handler and into callbacks
* Order assert.strictEqual() args per docs
* Remove console.log() calls
* Move test from `parallel` to `sequential` so `common.PORT` can be used
  without conflicting with OS-provided ports in other `parallel` tests

PR-URL: #13273
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
Trott authored and MylesBorins committed Aug 14, 2017
1 parent 7919eee commit 089bd3b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 86 deletions.
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();
}));
}

0 comments on commit 089bd3b

Please sign in to comment.