Skip to content

Commit b1081db

Browse files
theanarkhdanielleadams
authored andcommitted
test: fix test http upload timeout
PR-URL: #43935 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 808793e commit b1081db

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
// This tests setTimeout() by having multiple clients connecting and sending
2424
// data in random intervals. Clients are also randomly disconnecting until there
2525
// are no more clients left. If no false timeout occurs, this test has passed.
26-
require('../common');
26+
const common = require('../common');
2727
const http = require('http');
2828
const server = http.createServer();
2929
let connections = 0;
3030

31+
const ontimeout = common.mustNotCall('Unexpected timeout');
32+
3133
server.on('request', function(req, res) {
3234
req.socket.setTimeout(1000);
33-
req.socket.on('timeout', function() {
34-
throw new Error('Unexpected timeout');
35-
});
35+
req.socket.on('timeout', ontimeout);
3636
req.on('end', function() {
3737
connections--;
3838
res.writeHead(200);
39+
req.socket.off('timeout', ontimeout);
3940
res.end('done\n');
4041
if (connections === 0) {
4142
server.close();
@@ -47,7 +48,7 @@ server.on('request', function(req, res) {
4748
server.listen(0, function() {
4849
for (let i = 0; i < 10; i++) {
4950
connections++;
50-
51+
let count = 0;
5152
setTimeout(function() {
5253
const request = http.request({
5354
port: server.address().port,
@@ -56,13 +57,12 @@ server.listen(0, function() {
5657
});
5758

5859
function ping() {
59-
const nextPing = (Math.random() * 900).toFixed();
60-
if (nextPing > 600) {
60+
if (++count === 10) {
6161
request.end();
6262
return;
6363
}
6464
request.write('ping');
65-
setTimeout(ping, nextPing);
65+
setTimeout(ping, 300);
6666
}
6767
ping();
6868
}, i * 50);

0 commit comments

Comments
 (0)