Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 121b68a

Browse filesBrowse files
TrottMylesBorins
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 <santiago.gimeno@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent 4cf7dcf commit 121b68a
Copy full SHA for 121b68a

File tree

Expand file treeCollapse file tree

1 file changed

+12
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-17
lines changed
Open diff view settings
Collapse file
+12-17Lines changed: 12 additions & 17 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.