Skip to content

Commit 9d4a854

Browse files
Trotttargos
authored andcommitted
test: do not skip test-http-server-consumed-timeout
test-http-server-consumed-timeout has code to that causes it to be skipped on busy machines. Instead, use an exponential backoff for the timeout if the machine is busy. PR-URL: #30677 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a596a5d commit 9d4a854

1 file changed

Lines changed: 42 additions & 41 deletions

File tree

‎test/sequential/test-http-server-consumed-timeout.js‎

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,48 @@ const common = require('../common');
55
constassert=require('assert');
66
consthttp=require('http');
77

8-
lettime=Date.now();
98
letintervalWasInvoked=false;
10-
constTIMEOUT=common.platformTimeout(200);
11-
12-
constserver=http.createServer((req,res)=>{
13-
server.close();
14-
15-
res.writeHead(200);
16-
res.flushHeaders();
17-
18-
req.setTimeout(TIMEOUT,()=>{
19-
if(!intervalWasInvoked)
20-
returncommon.skip('interval was not invoked quickly enough for test');
21-
assert.fail('Request timeout should not fire');
9+
constTIMEOUT=common.platformTimeout(50);
10+
11+
runTest(TIMEOUT);
12+
13+
functionrunTest(timeoutDuration){
14+
constserver=http.createServer((req,res)=>{
15+
server.close();
16+
17+
res.writeHead(200);
18+
res.flushHeaders();
19+
20+
req.setTimeout(timeoutDuration,()=>{
21+
if(!intervalWasInvoked){
22+
// Interval wasn't invoked, probably because the machine is busy with
23+
// other things. Try again with a longer timeout.
24+
console.error(`Retrying with timeout of ${timeoutDuration*2}.`);
25+
returnsetImmediate(()=>{runTest(timeoutDuration*2);});
26+
}
27+
assert.fail('Request timeout should not fire');
28+
});
29+
30+
req.resume();
31+
req.once('end',()=>{
32+
res.end();
33+
});
2234
});
2335

24-
req.resume();
25-
req.once('end',()=>{
26-
res.end();
27-
});
28-
});
29-
30-
server.listen(0,common.mustCall(()=>{
31-
constreq=http.request({
32-
port: server.address().port,
33-
method: 'POST'
34-
},()=>{
35-
constinterval=setInterval(()=>{
36-
intervalWasInvoked=true;
37-
// If machine is busy enough that the interval takes more than TIMEOUT ms
38-
// to be invoked, skip the test.
39-
constnow=Date.now();
40-
if(now-time>TIMEOUT)
41-
returncommon.skip('interval is not invoked quickly enough for test');
42-
time=now;
43-
req.write('a');
44-
},common.platformTimeout(25));
45-
setTimeout(()=>{
46-
clearInterval(interval);
47-
req.end();
48-
},TIMEOUT);
49-
});
50-
req.write('.');
51-
}));
36+
server.listen(0,common.mustCall(()=>{
37+
constreq=http.request({
38+
port: server.address().port,
39+
method: 'POST'
40+
},()=>{
41+
constinterval=setInterval(()=>{
42+
intervalWasInvoked=true;
43+
req.write('a');
44+
},common.platformTimeout(25));
45+
setTimeout(()=>{
46+
clearInterval(interval);
47+
req.end();
48+
},timeoutDuration);
49+
});
50+
req.write('.');
51+
}));
52+
}

0 commit comments

Comments
 (0)