Skip to content

Commit 8848203

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

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 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();
@@ -57,7 +60,8 @@ server.listen(0, function() {
5760

5861
function ping() {
5962
const nextPing = (Math.random() * 900).toFixed();
60-
if (nextPing > 600) {
63+
// Do not set too big to prevent req.socket from emitting timeout
64+
if (nextPing > 300) {
6165
request.end();
6266
return;
6367
}

0 commit comments

Comments
 (0)