Browse Source

test: refactor http pipelined socket test

In test-http-incoming-pipelined-socket-destory:

* setTimeout() with no duration -> setImmediate()
* eliminate unneeded exit listener
* use common.mustCall()
* var -> const/let

PR-URL: https://github.com/nodejs/node/pull/10189
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
v4.x
Rich Trott 8 years ago
committed by Myles Borins
parent
commit
121b68a283
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 29
      test/parallel/test-http-incoming-pipelined-socket-destroy.js

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

@ -1,16 +1,17 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
var http = require('http'); const http = require('http');
var net = require('net'); const net = require('net');
const seeds = [ 3, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 ];
// Set up some timing issues where sockets can be destroyed // Set up some timing issues where sockets can be destroyed
// via either the req or res. // via either the req or res.
var server = http.createServer(function(req, res) { const server = http.createServer(common.mustCall(function(req, res) {
switch (req.url) { switch (req.url) {
case '/1': case '/1':
return setTimeout(function() { return setImmediate(function() {
req.socket.destroy(); req.socket.destroy();
server.emit('requestDone'); server.emit('requestDone');
}); });
@ -24,7 +25,7 @@ var server = http.createServer(function(req, res) {
// in one case, actually send a response in 2 chunks // in one case, actually send a response in 2 chunks
case '/3': case '/3':
res.write('hello '); res.write('hello ');
return setTimeout(function() { return setImmediate(function() {
res.end('world!'); res.end('world!');
server.emit('requestDone'); server.emit('requestDone');
}); });
@ -33,7 +34,7 @@ var server = http.createServer(function(req, res) {
res.destroy(); res.destroy();
server.emit('requestDone'); server.emit('requestDone');
} }
}); }, seeds.length));
// Make a bunch of requests pipelined on the same socket // Make a bunch of requests pipelined on the same socket
@ -47,10 +48,9 @@ function generator(seeds) {
} }
server.listen(0, function() { server.listen(0, common.mustCall(function() {
var seeds = [ 3, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 ]; const client = net.connect({ port: this.address().port });
var client = net.connect({ port: this.address().port }); let 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();
@ -60,9 +60,4 @@ server.listen(0, function() {
// immediately write the pipelined requests. // immediately write the pipelined requests.
// Some of these will not have a socket to destroy! // Some of these will not have a socket to destroy!
client.write(generator(seeds)); client.write(generator(seeds));
}); }));
process.on('exit', function(c) {
if (!c)
console.log('ok');
});

Loading…
Cancel
Save