Skip to content

Commit

Permalink
test: refactor test-http-client-timeout-option-with-agent
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Trott authored and targos committed Jan 30, 2019
1 parent c095106 commit 1d1d3f5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/parallel/test-http-client-timeout-option-with-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
});
Expand All @@ -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`
);
}));
Expand Down

0 comments on commit 1d1d3f5

Please sign in to comment.