Skip to content

Commit b1081db

Browse files
theanarkhdanielleadams
authored andcommitted
test: fix test http upload timeout
PR-URL: #43935 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
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‎

Lines changed: 8 additions & 8 deletions
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+
constcommon=require('../common');
2727
consthttp=require('http');
2828
constserver=http.createServer();
2929
letconnections=0;
3030

31+
constontimeout=common.mustNotCall('Unexpected timeout');
32+
3133
server.on('request',function(req,res){
3234
req.socket.setTimeout(1000);
33-
req.socket.on('timeout',function(){
34-
thrownewError('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(leti=0;i<10;i++){
4950
connections++;
50-
51+
letcount=0;
5152
setTimeout(function(){
5253
constrequest=http.request({
5354
port: server.address().port,
@@ -56,13 +57,12 @@ server.listen(0, function(){
5657
});
5758

5859
functionping(){
59-
constnextPing=(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)