Skip to content

Commit 1d1d3f5

Browse files
Trotttargos
authored andcommitted
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: #25746 PR-URL: #25752 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c095106 commit 1d1d3f5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

test/parallel/test-http-client-timeout-option-with-agent.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ server.listen(0, options.host, () => {
3030

3131
function doRequest() {
3232
options.port = server.address().port;
33+
const start = process.hrtime.bigint();
3334
const req = http.request(options);
34-
const start = Date.now();
3535
req.on('error', () => {
3636
// This space is intentionally left blank.
3737
});
@@ -40,11 +40,11 @@ function doRequest() {
4040
let timeout_events = 0;
4141
req.on('timeout', common.mustCall(() => {
4242
timeout_events += 1;
43-
const duration = Date.now() - start;
43+
const duration = process.hrtime.bigint() - start;
4444
// The timeout event cannot be precisely timed. It will delay
4545
// some number of milliseconds.
4646
assert.ok(
47-
duration >= HTTP_CLIENT_TIMEOUT,
47+
duration >= BigInt(HTTP_CLIENT_TIMEOUT * 1e6),
4848
`duration ${duration}ms less than timeout ${HTTP_CLIENT_TIMEOUT}ms`
4949
);
5050
}));

0 commit comments

Comments
 (0)