From 5baa4e01563c3f76790692acbe57d2be78cc0388 Mon Sep 17 00:00:00 2001 From: Thomas Hunter II Date: Thu, 8 Sep 2016 21:13:38 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/8458 Reviewed-By: Myles Borins Reviewed-By: Luigi Pinca Reviewed-By: Brian White Reviewed-By: Santiago Gimeno Reviewed-By: James M Snell --- test/parallel/test-net-server-try-ports.js | 54 ++++++---------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/test/parallel/test-net-server-try-ports.js b/test/parallel/test-net-server-try-ports.js index b0a877cf98f868..2aba5cef5b59ca 100644 --- a/test/parallel/test-net-server-try-ports.js +++ b/test/parallel/test-net-server-try-ports.js @@ -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); -}); +}));