Skip to content

Commit 3749dc6

Browse files
TrottFishrock123
authored andcommitted
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: #10189 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent e1d813f commit 3749dc6

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33

4-
var http = require('http');
5-
var net = require('net');
4+
const http = require('http');
5+
const net = require('net');
66

7+
const seeds = [ 3, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 ];
78

89
// Set up some timing issues where sockets can be destroyed
910
// via either the req or res.
10-
var server = http.createServer(function(req, res) {
11+
const server = http.createServer(common.mustCall(function(req, res) {
1112
switch (req.url) {
1213
case '/1':
13-
return setTimeout(function() {
14+
return setImmediate(function() {
1415
req.socket.destroy();
1516
server.emit('requestDone');
1617
});
@@ -24,7 +25,7 @@ var server = http.createServer(function(req, res) {
2425
// in one case, actually send a response in 2 chunks
2526
case '/3':
2627
res.write('hello ');
27-
return setTimeout(function() {
28+
return setImmediate(function() {
2829
res.end('world!');
2930
server.emit('requestDone');
3031
});
@@ -33,7 +34,7 @@ var server = http.createServer(function(req, res) {
3334
res.destroy();
3435
server.emit('requestDone');
3536
}
36-
});
37+
}, seeds.length));
3738

3839

3940
// Make a bunch of requests pipelined on the same socket
@@ -47,10 +48,9 @@ function generator(seeds) {
4748
}
4849

4950

50-
server.listen(0, function() {
51-
var seeds = [ 3, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 ];
52-
var client = net.connect({ port: this.address().port });
53-
var done = 0;
51+
server.listen(0, common.mustCall(function() {
52+
const client = net.connect({ port: this.address().port });
53+
let done = 0;
5454
server.on('requestDone', function() {
5555
if (++done === seeds.length) {
5656
server.close();
@@ -60,9 +60,4 @@ server.listen(0, function() {
6060
// immediately write the pipelined requests.
6161
// Some of these will not have a socket to destroy!
6262
client.write(generator(seeds));
63-
});
64-
65-
process.on('exit', function(c) {
66-
if (!c)
67-
console.log('ok');
68-
});
63+
}));

0 commit comments

Comments
 (0)