mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
test: refactor test-http-client-timeout-option-with-agent
* Switch from Date.now() to process.hrtime.bigint(). * Move start time recording to before the request is created, not after. Fixes: https://github.com/nodejs/node/issues/25746 PR-URL: https://github.com/nodejs/node/pull/25752 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
@@ -30,8 +30,8 @@ server.listen(0, options.host, () => {
|
||||
|
||||
function doRequest() {
|
||||
options.port = server.address().port;
|
||||
const start = process.hrtime.bigint();
|
||||
const req = http.request(options);
|
||||
const start = Date.now();
|
||||
req.on('error', () => {
|
||||
// This space is intentionally left blank.
|
||||
});
|
||||
@@ -40,11 +40,11 @@ function doRequest() {
|
||||
let timeout_events = 0;
|
||||
req.on('timeout', common.mustCall(() => {
|
||||
timeout_events += 1;
|
||||
const duration = Date.now() - start;
|
||||
const duration = process.hrtime.bigint() - start;
|
||||
// The timeout event cannot be precisely timed. It will delay
|
||||
// some number of milliseconds.
|
||||
assert.ok(
|
||||
duration >= HTTP_CLIENT_TIMEOUT,
|
||||
duration >= BigInt(HTTP_CLIENT_TIMEOUT * 1e6),
|
||||
`duration ${duration}ms less than timeout ${HTTP_CLIENT_TIMEOUT}ms`
|
||||
);
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user