Browse Source

test: favor strict equality in http tests

PR-URL: https://github.com/nodejs/node/pull/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>
v7.x
Rich Trott 8 years ago
parent
commit
c89b6ee347
  1. 2
      test/parallel/test-http-agent.js
  2. 2
      test/parallel/test-http-allow-req-after-204-res.js
  3. 2
      test/parallel/test-http-client-abort.js
  4. 2
      test/parallel/test-http-client-timeout-agent.js
  5. 2
      test/parallel/test-http-exceptions.js
  6. 2
      test/parallel/test-http-expect-continue.js
  7. 4
      test/parallel/test-http-get-pipeline-problem.js
  8. 2
      test/parallel/test-http-incoming-pipelined-socket-destroy.js
  9. 4
      test/parallel/test-http-legacy.js
  10. 2
      test/parallel/test-http-malformed-request.js
  11. 4
      test/parallel/test-http-response-multiheaders.js
  12. 12
      test/parallel/test-http-server.js
  13. 6
      test/parallel/test-http-set-cookies.js
  14. 6
      test/parallel/test-http-set-trailers.js
  15. 2
      test/parallel/test-http-timeout.js
  16. 6
      test/parallel/test-http-upgrade-server.js
  17. 2
      test/pummel/test-http-upload-timeout.js

2
test/parallel/test-http-agent.js

@ -19,7 +19,7 @@ server.listen(0, function() {
for (var j = 0; j < M; j++) { for (var j = 0; j < M; j++) {
http.get({ port: port, path: '/' }, function(res) { http.get({ port: port, path: '/' }, function(res) {
console.log('%d %d', responses, res.statusCode); console.log('%d %d', responses, res.statusCode);
if (++responses == N * M) { if (++responses === N * M) {
console.error('Received all responses, closing server'); console.error('Received all responses, closing server');
server.close(); server.close();
} }

2
test/parallel/test-http-allow-req-after-204-res.js

@ -28,7 +28,7 @@ function nextRequest() {
path: '/' path: '/'
}, function(response) { }, function(response) {
response.on('end', function() { response.on('end', function() {
if (methods.length == 0) { if (methods.length === 0) {
console.error('close server'); console.error('close server');
server.close(); server.close();
} else { } else {

2
test/parallel/test-http-client-abort.js

@ -37,7 +37,7 @@ server.listen(0, function() {
console.log('Client response code ' + res.statusCode); console.log('Client response code ' + res.statusCode);
res.resume(); res.resume();
if (++responses == N) { if (++responses === N) {
console.log('All clients connected, destroying.'); console.log('All clients connected, destroying.');
requests.forEach(function(outReq) { requests.forEach(function(outReq) {
console.log('abort'); console.log('abort');

2
test/parallel/test-http-client-timeout-agent.js

@ -71,6 +71,6 @@ server.listen(0, options.host, function() {
process.on('exit', function() { process.on('exit', function() {
console.error('done=%j sent=%j', requests_done, requests_sent); console.error('done=%j sent=%j', requests_done, requests_sent);
assert.ok(requests_done == requests_sent, assert.strictEqual(requests_done, requests_sent,
'timeout on http request called too much'); 'timeout on http request called too much');
}); });

2
test/parallel/test-http-exceptions.js

@ -20,6 +20,6 @@ var exception_count = 0;
process.on('uncaughtException', function(err) { process.on('uncaughtException', function(err) {
console.log('Caught an exception: ' + err); console.log('Caught an exception: ' + err);
if (err.name === 'AssertionError') throw err; if (err.name === 'AssertionError') throw err;
if (++exception_count == 4) process.exit(0); if (++exception_count === 4) process.exit(0);
}); });

2
test/parallel/test-http-expect-continue.js

@ -58,7 +58,7 @@ server.on('listening', function() {
assert.equal(body, test_res_body, 'Response body doesn\'t match.'); assert.equal(body, test_res_body, 'Response body doesn\'t match.');
assert.ok('abcd' in res.headers, 'Response headers missing.'); assert.ok('abcd' in res.headers, 'Response headers missing.');
outstanding_reqs--; outstanding_reqs--;
if (outstanding_reqs == 0) { if (outstanding_reqs === 0) {
server.close(); server.close();
process.exit(); process.exit();
} }

4
test/parallel/test-http-get-pipeline-problem.js

@ -19,7 +19,7 @@ var total = 10;
var requests = 0, responses = 0; var requests = 0, responses = 0;
var server = http.Server(function(req, res) { var server = http.Server(function(req, res) {
if (++requests == total) { if (++requests === total) {
server.close(); server.close();
} }
@ -51,7 +51,7 @@ server.listen(0, function() {
s.on('finish', function() { s.on('finish', function() {
console.error('done ' + x); console.error('done ' + x);
if (++responses == total) { if (++responses === total) {
checkFiles(); checkFiles();
} }
}); });

2
test/parallel/test-http-incoming-pipelined-socket-destroy.js

@ -52,7 +52,7 @@ server.listen(0, function() {
var client = net.connect({ port: this.address().port }); var client = net.connect({ port: this.address().port });
var done = 0; var done = 0;
server.on('requestDone', function() { server.on('requestDone', function() {
if (++done == seeds.length) { if (++done === seeds.length) {
server.close(); server.close();
} }
}); });

4
test/parallel/test-http-legacy.js

@ -9,7 +9,7 @@ var body0 = '';
var body1 = ''; var body1 = '';
var server = http.createServer(function(req, res) { var server = http.createServer(function(req, res) {
if (responses_sent == 0) { if (responses_sent === 0) {
assert.equal('GET', req.method); assert.equal('GET', req.method);
assert.equal('/hello', url.parse(req.url).pathname); assert.equal('/hello', url.parse(req.url).pathname);
@ -21,7 +21,7 @@ var server = http.createServer(function(req, res) {
assert.equal('bar', req.headers['foo']); assert.equal('bar', req.headers['foo']);
} }
if (responses_sent == 1) { if (responses_sent === 1) {
assert.equal('POST', req.method); assert.equal('POST', req.method);
assert.equal('/world', url.parse(req.url).pathname); assert.equal('/world', url.parse(req.url).pathname);
this.close(); this.close();

2
test/parallel/test-http-malformed-request.js

@ -18,7 +18,7 @@ var server = http.createServer(function(req, res) {
res.write('Hello World'); res.write('Hello World');
res.end(); res.end();
if (++nrequests_completed == nrequests_expected) server.close(); if (++nrequests_completed === nrequests_expected) server.close();
}); });
server.listen(0); server.listen(0);

4
test/parallel/test-http-response-multiheaders.js

@ -30,12 +30,12 @@ const norepeat = [
const server = http.createServer(function(req, res) { const server = http.createServer(function(req, res) {
var num = req.headers['x-num']; var num = req.headers['x-num'];
if (num == 1) { if (num === '1') {
for (const name of norepeat) { for (const name of norepeat) {
res.setHeader(name, ['A', 'B']); res.setHeader(name, ['A', 'B']);
} }
res.setHeader('X-A', ['A', 'B']); res.setHeader('X-A', ['A', 'B']);
} else if (num == 2) { } else if (num === '2') {
const headers = {}; const headers = {};
for (const name of norepeat) { for (const name of norepeat) {
headers[name] = ['A', 'B']; headers[name] = ['A', 'B'];

12
test/parallel/test-http-server.js

@ -15,23 +15,23 @@ var server = http.createServer(function(req, res) {
res.id = request_number; res.id = request_number;
req.id = request_number++; req.id = request_number++;
if (req.id == 0) { if (req.id === 0) {
assert.equal('GET', req.method); assert.equal('GET', req.method);
assert.equal('/hello', url.parse(req.url).pathname); assert.equal('/hello', url.parse(req.url).pathname);
assert.equal('world', qs.parse(url.parse(req.url).query).hello); assert.equal('world', qs.parse(url.parse(req.url).query).hello);
assert.equal('b==ar', qs.parse(url.parse(req.url).query).foo); 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('POST', req.method);
assert.equal('/quit', url.parse(req.url).pathname); assert.equal('/quit', url.parse(req.url).pathname);
} }
if (req.id == 2) { if (req.id === 2) {
assert.equal('foo', req.headers['x-x']); assert.equal('foo', req.headers['x-x']);
} }
if (req.id == 3) { if (req.id === 3) {
assert.equal('bar', req.headers['x-x']); assert.equal('bar', req.headers['x-x']);
this.close(); this.close();
} }
@ -60,12 +60,12 @@ server.on('listening', function() {
c.on('data', function(chunk) { c.on('data', function(chunk) {
server_response += chunk; server_response += chunk;
if (requests_sent == 1) { if (requests_sent === 1) {
c.write('POST /quit HTTP/1.1\r\n\r\n'); c.write('POST /quit HTTP/1.1\r\n\r\n');
requests_sent += 1; 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' + 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'); 'GET / HTTP/1.1\r\nX-X: bar\r\n\r\n');
// Note: we are making the connection half-closed here // Note: we are making the connection half-closed here

6
test/parallel/test-http-set-cookies.js

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

6
test/parallel/test-http-set-trailers.js

@ -35,7 +35,7 @@ server.on('listening', function() {
c.end(); c.end();
assert.ok(!/x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.'); assert.ok(!/x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.');
outstanding_reqs--; outstanding_reqs--;
if (outstanding_reqs == 0) { if (outstanding_reqs === 0) {
server.close(); server.close();
process.exit(); process.exit();
} }
@ -66,7 +66,7 @@ server.on('listening', function() {
/0\r\nx-foo: bar\r\n\r\n$/.test(res_buffer), /0\r\nx-foo: bar\r\n\r\n$/.test(res_buffer),
'No trailer in HTTP/1.1 response.' 'No trailer in HTTP/1.1 response.'
); );
if (outstanding_reqs == 0) { if (outstanding_reqs === 0) {
server.close(); server.close();
process.exit(); process.exit();
} }
@ -85,7 +85,7 @@ server.on('listening', function() {
//console.log(res.trailers); //console.log(res.trailers);
assert.ok('x-foo' in res.trailers, 'Client doesn\'t see trailers.'); assert.ok('x-foo' in res.trailers, 'Client doesn\'t see trailers.');
outstanding_reqs--; outstanding_reqs--;
if (outstanding_reqs == 0) { if (outstanding_reqs === 0) {
server.close(); server.close();
process.exit(); process.exit();
} }

2
test/parallel/test-http-timeout.js

@ -29,7 +29,7 @@ server.listen(0, function() {
res.on('end', function() { res.on('end', function() {
count++; count++;
if (count == 11) { if (count === 11) {
server.close(); server.close();
} }
}); });

6
test/parallel/test-http-upgrade-server.js

@ -38,7 +38,7 @@ function testServer() {
socket.on('data', function(d) { socket.on('data', function(d) {
var data = d.toString('utf8'); var data = d.toString('utf8');
if (data == 'kill') { if (data === 'kill') {
socket.end(); socket.end();
} else { } else {
socket.write(data, 'utf8'); socket.write(data, 'utf8');
@ -78,11 +78,11 @@ function test_upgrade_with_listener() {
assert.equal('string', typeof data); assert.equal('string', typeof data);
if (state == 1) { if (state === 1) {
assert.equal('HTTP/1.1 101', data.substr(0, 12)); assert.equal('HTTP/1.1 101', data.substr(0, 12));
assert.equal('WjN}|M(6', request_upgradeHead.toString('utf8')); assert.equal('WjN}|M(6', request_upgradeHead.toString('utf8'));
conn.write('test', 'utf8'); conn.write('test', 'utf8');
} else if (state == 2) { } else if (state === 2) {
assert.equal('test', data); assert.equal('test', data);
conn.write('kill', 'utf8'); conn.write('kill', 'utf8');
} }

2
test/pummel/test-http-upload-timeout.js

@ -16,7 +16,7 @@ server.on('request', function(req, res) {
connections--; connections--;
res.writeHead(200); res.writeHead(200);
res.end('done\n'); res.end('done\n');
if (connections == 0) { if (connections === 0) {
server.close(); server.close();
} }
}); });

Loading…
Cancel
Save