Skip to content

Commit d9d6975

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

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ let connections = 0;
3030

3131
server.on('request', function(req, res) {
3232
req.socket.setTimeout(1000);
33-
req.socket.on('timeout', function() {
33+
const ontimeout = function() {
3434
throw new Error('Unexpected timeout');
35-
});
35+
};
36+
req.socket.on('timeout', ontimeout);
3637
req.on('end', function() {
3738
connections--;
3839
res.writeHead(200);
40+
req.socket.off('timeout', ontimeout);
3941
res.end('done\n');
4042
if (connections === 0) {
4143
server.close();
@@ -57,7 +59,8 @@ server.listen(0, function() {
5759

5860
function ping() {
5961
const nextPing = (Math.random() * 900).toFixed();
60-
if (nextPing > 600) {
62+
// Do not set too big to prevent req.socket from emitting timeout
63+
if (nextPing > 300) {
6164
request.end();
6265
return;
6366
}

0 commit comments

Comments
 (0)