Skip to content

Commit

Permalink
test: favor strict equality in http tests
Browse files Browse the repository at this point in the history
PR-URL: #8151
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Trott authored and Myles Borins committed Oct 10, 2016
1 parent 3702f1f commit ba7c13b
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion test/parallel/test-http-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ server.listen(0, function() {
for (var j = 0; j < M; j++) {
http.get({ port: port, path: '/' }, function(res) {
console.log('%d %d', responses, res.statusCode);
if (++responses == N * M) {
if (++responses === N * M) {
console.error('Received all responses, closing server');
server.close();
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-allow-req-after-204-res.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function nextRequest() {
path: '/'
}, function(response) {
response.on('end', function() {
if (methods.length == 0) {
if (methods.length === 0) {
console.error('close server');
server.close();
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-client-abort.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ server.listen(0, function() {
console.log('Client response code ' + res.statusCode);

res.resume();
if (++responses == N) {
if (++responses === N) {
console.log('All clients connected, destroying.');
requests.forEach(function(outReq) {
console.log('abort');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-client-timeout-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ server.listen(0, options.host, function() {

process.on('exit', function() {
console.error('done=%j sent=%j', requests_done, requests_sent);
assert.ok(requests_done == requests_sent,
'timeout on http request called too much');
assert.strictEqual(requests_done, requests_sent,
'timeout on http request called too much');
});
2 changes: 1 addition & 1 deletion test/parallel/test-http-exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ var exception_count = 0;
process.on('uncaughtException', function(err) {
console.log('Caught an exception: ' + err);
if (err.name === 'AssertionError') throw err;
if (++exception_count == 4) process.exit(0);
if (++exception_count === 4) process.exit(0);
});

2 changes: 1 addition & 1 deletion test/parallel/test-http-expect-continue.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ server.on('listening', function() {
assert.equal(body, test_res_body, 'Response body doesn\'t match.');
assert.ok('abcd' in res.headers, 'Response headers missing.');
outstanding_reqs--;
if (outstanding_reqs == 0) {
if (outstanding_reqs === 0) {
server.close();
process.exit();
}
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-get-pipeline-problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var total = 10;
var requests = 0, responses = 0;

var server = http.Server(function(req, res) {
if (++requests == total) {
if (++requests === total) {
server.close();
}

Expand Down Expand Up @@ -51,7 +51,7 @@ server.listen(0, function() {

s.on('finish', function() {
console.error('done ' + x);
if (++responses == total) {
if (++responses === total) {
checkFiles();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ server.listen(0, function() {
var client = net.connect({ port: this.address().port });
var done = 0;
server.on('requestDone', function() {
if (++done == seeds.length) {
if (++done === seeds.length) {
server.close();
}
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var body0 = '';
var body1 = '';

var server = http.createServer(function(req, res) {
if (responses_sent == 0) {
if (responses_sent === 0) {
assert.equal('GET', req.method);
assert.equal('/hello', url.parse(req.url).pathname);

Expand All @@ -22,7 +22,7 @@ var server = http.createServer(function(req, res) {
assert.equal('bar', req.headers['foo']);
}

if (responses_sent == 1) {
if (responses_sent === 1) {
assert.equal('POST', req.method);
assert.equal('/world', url.parse(req.url).pathname);
this.close();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-malformed-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var server = http.createServer(function(req, res) {
res.write('Hello World');
res.end();

if (++nrequests_completed == nrequests_expected) server.close();
if (++nrequests_completed === nrequests_expected) server.close();
});
server.listen(0);

Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ var server = http.createServer(function(req, res) {
res.id = request_number;
req.id = request_number++;

if (req.id == 0) {
if (req.id === 0) {
assert.equal('GET', req.method);
assert.equal('/hello', url.parse(req.url).pathname);
assert.equal('world', qs.parse(url.parse(req.url).query).hello);
assert.equal('b==ar', qs.parse(url.parse(req.url).query).foo);
}

if (req.id == 1) {
if (req.id === 1) {
assert.equal('POST', req.method);
assert.equal('/quit', url.parse(req.url).pathname);
}

if (req.id == 2) {
if (req.id === 2) {
assert.equal('foo', req.headers['x-x']);
}

if (req.id == 3) {
if (req.id === 3) {
assert.equal('bar', req.headers['x-x']);
this.close();
}
Expand Down Expand Up @@ -60,12 +60,12 @@ server.on('listening', function() {
c.on('data', function(chunk) {
server_response += chunk;

if (requests_sent == 1) {
if (requests_sent === 1) {
c.write('POST /quit HTTP/1.1\r\n\r\n');
requests_sent += 1;
}

if (requests_sent == 2) {
if (requests_sent === 2) {
c.write('GET / HTTP/1.1\r\nX-X: foo\r\n\r\n' +
'GET / HTTP/1.1\r\nX-X: bar\r\n\r\n');
// Note: we are making the connection half-closed here
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-http-set-cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var http = require('http');
var nresponses = 0;

var server = http.createServer(function(req, res) {
if (req.url == '/one') {
if (req.url === '/one') {
res.writeHead(200, [['set-cookie', 'A'],
['content-type', 'text/plain']]);
res.end('one\n');
Expand Down Expand Up @@ -34,7 +34,7 @@ server.on('listening', function() {
});

res.on('end', function() {
if (++nresponses == 2) {
if (++nresponses === 2) {
server.close();
}
});
Expand All @@ -51,7 +51,7 @@ server.on('listening', function() {
});

res.on('end', function() {
if (++nresponses == 2) {
if (++nresponses === 2) {
server.close();
}
});
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-http-set-trailers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ server.on('listening', function() {
c.end();
assert.ok(!/x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.');
outstanding_reqs--;
if (outstanding_reqs == 0) {
if (outstanding_reqs === 0) {
server.close();
process.exit();
}
Expand Down Expand Up @@ -66,7 +66,7 @@ server.on('listening', function() {
/0\r\nx-foo: bar\r\n\r\n$/.test(res_buffer),
'No trailer in HTTP/1.1 response.'
);
if (outstanding_reqs == 0) {
if (outstanding_reqs === 0) {
server.close();
process.exit();
}
Expand All @@ -85,7 +85,7 @@ server.on('listening', function() {
//console.log(res.trailers);
assert.ok('x-foo' in res.trailers, 'Client doesn\'t see trailers.');
outstanding_reqs--;
if (outstanding_reqs == 0) {
if (outstanding_reqs === 0) {
server.close();
process.exit();
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ server.listen(0, function() {
res.on('end', function() {
count++;

if (count == 11) {
if (count === 11) {
server.close();
}
});
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-http-upgrade-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function testServer() {

socket.on('data', function(d) {
var data = d.toString('utf8');
if (data == 'kill') {
if (data === 'kill') {
socket.end();
} else {
socket.write(data, 'utf8');
Expand Down Expand Up @@ -78,11 +78,11 @@ function test_upgrade_with_listener() {

assert.equal('string', typeof data);

if (state == 1) {
if (state === 1) {
assert.equal('HTTP/1.1 101', data.substr(0, 12));
assert.equal('WjN}|M(6', request_upgradeHead.toString('utf8'));
conn.write('test', 'utf8');
} else if (state == 2) {
} else if (state === 2) {
assert.equal('test', data);
conn.write('kill', 'utf8');
}
Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-http-upload-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ server.on('request', function(req, res) {
connections--;
res.writeHead(200);
res.end('done\n');
if (connections == 0) {
if (connections === 0) {
server.close();
}
});
Expand Down

0 comments on commit ba7c13b

Please sign in to comment.