-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: clean up net server try ports test
* Replace var's with const and let * Replace boolean flags with common.mustCall() * Using stricter comparisons * Fixed typo in comment PR-URL: #8458 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
5387735
commit 5baa4e0
Showing
1 changed file
with
13 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,24 @@ | ||
'use strict'; | ||
// This tests binds to one port, then attempts to start a server on that | ||
// 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. | ||
require('../common'); | ||
var assert = require('assert'); | ||
var net = require('net'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
var server1listening = false; | ||
var server2listening = false; | ||
var server2eaddrinuse = false; | ||
const server1 = net.Server(); | ||
|
||
var server1 = net.Server(function(socket) { | ||
socket.destroy(); | ||
}); | ||
const server2 = net.Server(); | ||
|
||
var server2 = net.Server(function(socket) { | ||
socket.destroy(); | ||
}); | ||
|
||
var server2errors = 0; | ||
server2.on('error', function(e) { | ||
server2errors++; | ||
console.error('server2 error'); | ||
|
||
if (e.code == 'EADDRINUSE') { | ||
server2eaddrinuse = true; | ||
} | ||
|
||
server2.listen(0, function() { | ||
console.error('server2 listening'); | ||
server2listening = true; | ||
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, function() { | ||
console.error('server1 listening'); | ||
server1listening = true; | ||
server1.listen(0, common.mustCall(function() { | ||
// This should make server2 emit EADDRINUSE | ||
server2.listen(this.address().port); | ||
}); | ||
|
||
|
||
process.on('exit', function() { | ||
assert.equal(1, server2errors); | ||
assert.ok(server2eaddrinuse); | ||
assert.ok(server2listening); | ||
assert.ok(server1listening); | ||
}); | ||
})); |