Skip to content
Closed
Changes from 1 commit
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
Next Next commit
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
  • Loading branch information
Trott committed Oct 5, 2016
commit 1ffb714a3ff4246d0556069c18fab46fe088fa7c
38 changes: 19 additions & 19 deletions test/parallel/test-net-server-max-connections.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'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;
const N = 20;
var count = 0;
var closes = 0;
var waits = [];
const waits = [];

var server = net.createServer(function(connection) {
const server = net.createServer(function(connection) {
console.error('connect %d', count++);
connection.write('hello');
waits.push(function() { connection.end(); });

@santigimeno santigimeno Oct 5, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe wrap the callback with common.mustCall(function() {}, N/2) and remove the count variable as it's not being used except for the debug log. Also, I would probably remove the logs from the code.

Expand All @@ -29,7 +29,7 @@ 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() {
Expand All @@ -42,10 +42,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) {
Expand All @@ -58,11 +58,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`);
}
});
});
Expand All @@ -86,5 +86,5 @@ function makeConnection(index) {


process.on('exit', function() {
assert.equal(N, closes);
assert.strictEqual(N, closes);
});