0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 15:30:56 +01:00
nodejs/test/sequential/test-http-server-consumed-timeout.js
Rich Trott 8331f571ed test: remove undefined function
`common.fail()` no longer exists as its functionality is now in
`assert.fail()`. Replace only two instances in the code base with
`assert.fail()`.

PR-URL: https://github.com/nodejs/node/pull/17845
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
2017-12-26 10:26:07 +08:00

52 lines
1.2 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
let time = Date.now();
let intervalWasInvoked = false;
const TIMEOUT = common.platformTimeout(200);
const server = http.createServer((req, res) => {
server.close();
res.writeHead(200);
res.flushHeaders();
req.setTimeout(TIMEOUT, () => {
if (!intervalWasInvoked)
return common.skip('interval was not invoked quickly enough for test');
assert.fail('Request timeout should not fire');
});
req.resume();
req.once('end', () => {
res.end();
});
});
server.listen(0, common.mustCall(() => {
const req = http.request({
port: server.address().port,
method: 'POST'
}, (res) => {
const interval = setInterval(() => {
intervalWasInvoked = true;
// If machine is busy enough that the interval takes more than TIMEOUT ms
// to be invoked, skip the test.
const now = Date.now();
if (now - time > TIMEOUT)
return common.skip('interval is not invoked quickly enough for test');
time = now;
req.write('a');
}, common.platformTimeout(25));
setTimeout(() => {
clearInterval(interval);
req.end();
}, TIMEOUT);
});
req.write('.');
}));