Skip to content

Commit f0d1d29

Browse files
committed
test: fix test http upload timeout
1 parent 95d9140 commit f0d1d29

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ const http = require('http');
2828
const server = http.createServer();
2929
let connections = 0;
3030

31+
function ontimeout() {
32+
throw new Error('Unexpected timeout');
33+
}
34+
3135
server.on('request', function(req, res) {
3236
req.socket.setTimeout(1000);
33-
req.socket.on('timeout', function() {
34-
throw new Error('Unexpected timeout');
35-
});
37+
req.socket.on('timeout', ontimeout);
3638
req.on('end', function() {
3739
connections--;
3840
res.writeHead(200);
41+
req.socket.off('timeout', ontimeout);
3942
res.end('done\n');
4043
if (connections === 0) {
4144
server.close();
@@ -47,7 +50,7 @@ server.on('request', function(req, res) {
4750
server.listen(0, function() {
4851
for (let i = 0; i < 10; i++) {
4952
connections++;
50-
53+
let count = 0;
5154
setTimeout(function() {
5255
const request = http.request({
5356
port: server.address().port,
@@ -56,13 +59,12 @@ server.listen(0, function() {
5659
});
5760

5861
function ping() {
59-
const nextPing = (Math.random() * 900).toFixed();
60-
if (nextPing > 600) {
62+
if (++count === 10) {
6163
request.end();
6264
return;
6365
}
6466
request.write('ping');
65-
setTimeout(ping, nextPing);
67+
setTimeout(ping, 300);
6668
}
6769
ping();
6870
}, i * 50);

0 commit comments

Comments
 (0)