Skip to content

Commit 7d71465

Browse files
duncanhealycodebytere
authored andcommitted
test: fix flaky test-fs-stat-bigint
Change test limit for atime from 2ms to 5ms. Add comment explaining why the wiggle room is needed. Fixes: #24593 PR-URL: #30437 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent ca6fce0 commit 7d71465

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

test/parallel/test-fs-stat-bigint.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ tmpdir.refresh();
1313

1414
let testIndex = 0;
1515

16+
// It's possible that the file stats are updated between the two statSync()
17+
// calls so allow for a small difference.
18+
const allowableDelta = 5;
19+
1620
function getFilename() {
1721
const filename = path.join(tmpdir.path, `test-file-${++testIndex}`);
1822
fs.writeFileSync(filename, 'test');
@@ -26,8 +30,8 @@ function verifyStats(bigintStats, numStats) {
2630
const time = val.getTime();
2731
const time2 = bigintStats[key].getTime();
2832
assert(
29-
Math.abs(time - time2) < 2,
30-
`difference of ${key}.getTime() should < 2.\n` +
33+
Math.abs(time - time2) < allowableDelta,
34+
`difference of ${key}.getTime() should < ${allowableDelta}.\n` +
3135
`Number version ${time}, BigInt version ${time2}n`);
3236
} else if (key === 'mode') {
3337
assert.strictEqual(bigintStats[key], BigInt(val));
@@ -65,17 +69,14 @@ function verifyStats(bigintStats, numStats) {
6569
const nsFromBigInt = bigintStats[nsKey];
6670
const msFromBigIntNs = Number(nsFromBigInt / (10n ** 6n));
6771
const msFromNum = numStats[key];
68-
// The difference between the millisecond-precision values should be
69-
// smaller than 2
72+
7073
assert(
71-
Math.abs(msFromNum - Number(msFromBigInt)) < 2,
74+
Math.abs(msFromNum - Number(msFromBigInt)) < allowableDelta,
7275
`Number version ${key} = ${msFromNum}, ` +
7376
`BigInt version ${key} = ${msFromBigInt}n`);
74-
// The difference between the millisecond-precision value and the
75-
// nanosecond-precision value scaled down to milliseconds should be
76-
// smaller than 2
77+
7778
assert(
78-
Math.abs(msFromNum - Number(msFromBigIntNs)) < 2,
79+
Math.abs(msFromNum - Number(msFromBigIntNs)) < allowableDelta,
7980
`Number version ${key} = ${msFromNum}, ` +
8081
`BigInt version ${nsKey} = ${nsFromBigInt}n` +
8182
` = ${msFromBigIntNs}ms`);

0 commit comments

Comments
 (0)