diff options
author | Rich Trott <rtrott@gmail.com> | 2016-10-04 16:16:38 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-10-06 14:47:52 -0700 |
commit | eff6205fd0b532c015b600049e637780afabff07 (patch) | |
tree | ea1ee7d951274c9d85f1d72a68b132161189c1c9 /test | |
parent | bf0bcf463de56497509757fb3d1ad9c9ea7f9f58 (diff) | |
download | android-node-v8-eff6205fd0b532c015b600049e637780afabff07.tar.gz android-node-v8-eff6205fd0b532c015b600049e637780afabff07.tar.bz2 android-node-v8-eff6205fd0b532c015b600049e637780afabff07.zip |
test: refactor test-net-server-max-connections
The test timed out on Windows in CI. Made the following changes:
* reduced total connections from 200 to 20
* var -> const
* string concatenation -> templates
* assert.equal -> assert.strictEqual
PR-URL: https://github.com/nodejs/node/pull/8931
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-net-server-max-connections.js | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/test/parallel/test-net-server-max-connections.js b/test/parallel/test-net-server-max-connections.js index 661c18113b..99d3b345f4 100644 --- a/test/parallel/test-net-server-max-connections.js +++ b/test/parallel/test-net-server-max-connections.js @@ -1,23 +1,21 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); -var net = require('net'); +const net = require('net'); -// This test creates 200 connections to a server and sets the server's -// maxConnections property to 100. The first 100 connections make it through -// and the last 100 connections are rejected. +// This test creates 20 connections to a server and sets the server's +// maxConnections property to 10. The first 10 connections make it through +// and the last 10 connections are rejected. -var N = 200; -var count = 0; +const N = 20; var closes = 0; -var waits = []; +const waits = []; -var server = net.createServer(function(connection) { - console.error('connect %d', count++); +const server = net.createServer(common.mustCall(function(connection) { connection.write('hello'); waits.push(function() { connection.end(); }); -}); +}, N / 2)); server.listen(0, function() { makeConnection(0); @@ -25,11 +23,9 @@ server.listen(0, function() { server.maxConnections = N / 2; -console.error('server.maxConnections = %d', server.maxConnections); - function makeConnection(index) { - var c = net.createConnection(server.address().port); + const c = net.createConnection(server.address().port); var gotData = false; c.on('connect', function() { @@ -42,10 +38,10 @@ function makeConnection(index) { closes++; if (closes < N / 2) { - assert.ok(server.maxConnections <= index, - index + - ' was one of the first closed connections ' + - 'but shouldnt have been'); + assert.ok( + server.maxConnections <= index, + `${index} should not have been one of the first closed connections` + ); } if (closes === N / 2) { @@ -58,11 +54,11 @@ function makeConnection(index) { } if (index < server.maxConnections) { - assert.equal(true, gotData, - index + ' didn\'t get data, but should have'); + assert.strictEqual(true, gotData, + `${index} didn't get data, but should have`); } else { - assert.equal(false, gotData, - index + ' got data, but shouldn\'t have'); + assert.strictEqual(false, gotData, + `${index} got data, but shouldn't have`); } }); }); @@ -86,5 +82,5 @@ function makeConnection(index) { process.on('exit', function() { - assert.equal(N, closes); + assert.strictEqual(N, closes); }); |