Skip to content

Commit a7ab63c

Browse files
deokjinkimjuanarbol
authored andcommitted
test: use process.hrtime.bigint instead of process.hrtime
`process.hrtime` is legacy. So replace `process.hrtime` with `process.hrtime.bigint` in test. Refs: https://github.com/nodejs/node/blob/main/doc/api/process.md#processhrtimetime Signed-off-by: Deokjin Kim <[email protected]> PR-URL: #45877 Refs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent b489b13 commit a7ab63c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

test/parallel/test-http2-session-timeout.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ if (!common.hasCrypto)
55
common.skip('missing crypto');
66
const assert = require('assert');
77
const http2 = require('http2');
8+
const hrtime = process.hrtime.bigint;
9+
const NS_PER_MS = 1_000_000n;
810

911
let requests = 0;
1012
const mustNotCall = () => {
@@ -14,7 +16,7 @@ const mustNotCall = () => {
1416
const server = http2.createServer();
1517
// Disable server timeout until first request. We will set the timeout based on
1618
// how long the first request takes.
17-
server.timeout = 0;
19+
server.timeout = 0n;
1820

1921
server.on('request', (req, res) => res.end());
2022
server.on('timeout', mustNotCall);
@@ -24,7 +26,7 @@ server.listen(0, common.mustCall(() => {
2426

2527
const url = `http://localhost:${port}`;
2628
const client = http2.connect(url);
27-
let startTime = process.hrtime();
29+
let startTime = hrtime();
2830
makeReq();
2931

3032
function makeReq() {
@@ -40,17 +42,17 @@ server.listen(0, common.mustCall(() => {
4042
requests += 1;
4143

4244
request.on('end', () => {
43-
const diff = process.hrtime(startTime);
44-
const milliseconds = (diff[0] * 1e3 + diff[1] / 1e6);
45-
if (server.timeout === 0) {
45+
const diff = hrtime() - startTime;
46+
const milliseconds = diff / NS_PER_MS;
47+
if (server.timeout === 0n) {
4648
// Set the timeout now. First connection will take significantly longer
4749
// than subsequent connections, so using the duration of the first
4850
// connection as the timeout should be robust. Double it anyway for good
4951
// measure.
50-
server.timeout = milliseconds * 2;
51-
startTime = process.hrtime();
52+
server.timeout = milliseconds * 2n;
53+
startTime = hrtime();
5254
makeReq();
53-
} else if (milliseconds < server.timeout * 2) {
55+
} else if (milliseconds < server.timeout * 2n) {
5456
makeReq();
5557
} else {
5658
server.removeListener('timeout', mustNotCall);

0 commit comments

Comments
 (0)