Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
19fbcc1
doc: merge CODE_OF_CONDUCT.md and coc.md
DavenportEmma Feb 13, 2020
82404d7
doc: change underscore to hyphen in file name
DavenportEmma Feb 13, 2020
7c306dc
doc: move guide file to doc/guides
DavenportEmma Feb 13, 2020
63535cd
doc: update guide name
DavenportEmma Feb 13, 2020
fd5de31
doc: move guides to appropriate directory
DavenportEmma Feb 13, 2020
0e71d06
doc: move files from doc/ to doc/guides
DavenportEmma Feb 13, 2020
aa9de2a
doc: rename and move STYLE_GUIDE.md
DavenportEmma Feb 13, 2020
36b7c22
update broken links in CODE_OF_CONDUCT.md
DavenportEmma Feb 13, 2020
09b6894
doc: update foundation name in onboarding
tniessen Feb 10, 2020
5e41765
doc: expand C++ README with information about exception handling
addaleax Feb 10, 2020
e5e011d
doc: add directions to mark a release line as lts
Feb 10, 2020
d565041
test: improve test-fs-stat-bigint
Trott Feb 11, 2020
9da57a8
test: fix flaky parallel/test-repl-history-navigation test
BridgeAR Feb 9, 2020
bc55b57
lib: fix few comment typos in fs/watchers.js
lundibundi Feb 9, 2020
b9a7625
stream: removed outdated TODO
ronag Feb 8, 2020
26cb448
doc: fix default server timeout description for https
puzpuzpuz Feb 8, 2020
9179141
doc: update contact email for @ryzokuken
ryzokuken Feb 7, 2020
94eb0f9
doc: fix typo on fs docs
juanarbol Feb 3, 2020
611a158
worker: add support for .cjs extension
aduh95 Feb 6, 2020
9e805b1
doc: add prerequisites information for Arch
ryzokuken Feb 7, 2020
d0ed431
benchmark: swap var for let in benchmarks
RamirezAlex Jul 31, 2019
4bf888d
benchmark: use let instead of var
dnlup Jan 31, 2020
9cbf6af
crypto: fix performance regression
ronag Feb 11, 2020
13c05cd
doc: add glossary.md
gengjiawen May 1, 2019
9a1c19b
test: mark test-fs-stat-bigint flaky on FreeBSD
Trott Feb 11, 2020
0875837
stream: fix async iterator destroyed error order
ronag Jan 11, 2020
ad79237
doc: merge CODE_OF_CONDUCT.md and coc.md
DavenportEmma Feb 13, 2020
e1bd95d
doc: change underscore to hyphen in file name
DavenportEmma Feb 13, 2020
07bc3ee
doc: move guide file to doc/guides
DavenportEmma Feb 13, 2020
12354ee
doc: update guide name
DavenportEmma Feb 13, 2020
695f089
doc: move guides to appropriate directory
DavenportEmma Feb 13, 2020
ee9573c
doc: move files from doc/ to doc/guides
DavenportEmma Feb 13, 2020
64397e2
doc: rename and move STYLE_GUIDE.md
DavenportEmma Feb 13, 2020
d50459f
update broken links in CODE_OF_CONDUCT.md
DavenportEmma Feb 13, 2020
6d9b3d8
Revert "doc: merge CODE_OF_CONDUCT.md and coc.md"
DavenportEmma Feb 14, 2020
1c6cf86
Merge branch 'issue31741' of github.com:ConorDavenport/node into issu…
DavenportEmma Feb 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: improve test-fs-stat-bigint
Remove magic number and measure amount of difference should be allowable
between consecutive stat() calls.

PR-URL: #31726
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
Trott authored and addaleax committed Feb 13, 2020
commit d5650418762ed3562db8f7fabbca575a2fde35a5
111 changes: 60 additions & 51 deletions test/parallel/test-fs-stat-bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,23 @@ tmpdir.refresh();

let testIndex = 0;

// It's possible that the file stats are updated between the two statSync()
// calls so allow for a small difference.
const allowableDelta = 5;

function getFilename() {
const filename = path.join(tmpdir.path, `test-file-${++testIndex}`);
fs.writeFileSync(filename, 'test');
return filename;
}

function verifyStats(bigintStats, numStats) {
function verifyStats(bigintStats, numStats, allowableDelta) {
// allowableDelta: It's possible that the file stats are updated between the
// two stat() calls so allow for a small difference.
for (const key of Object.keys(numStats)) {
const val = numStats[key];
if (isDate(val)) {
const time = val.getTime();
const time2 = bigintStats[key].getTime();
assert(
Math.abs(time - time2) < allowableDelta,
`difference of ${key}.getTime() should < ${allowableDelta}.\n` +
time - time2 <= allowableDelta,
`difference of ${key}.getTime() should <= ${allowableDelta}.\n` +
`Number version ${time}, BigInt version ${time2}n`);
} else if (key === 'mode') {
assert.strictEqual(bigintStats[key], BigInt(val));
Expand Down Expand Up @@ -71,15 +69,16 @@ function verifyStats(bigintStats, numStats) {
const msFromNum = numStats[key];

assert(
Math.abs(msFromNum - Number(msFromBigInt)) < allowableDelta,
msFromNum - Number(msFromBigInt) <= allowableDelta,
`Number version ${key} = ${msFromNum}, ` +
`BigInt version ${key} = ${msFromBigInt}n`);
`BigInt version ${key} = ${msFromBigInt}n, ` +
`Allowable delta = ${allowableDelta}`);

assert(
Math.abs(msFromNum - Number(msFromBigIntNs)) < allowableDelta,
msFromNum - Number(msFromBigIntNs) <= allowableDelta,
`Number version ${key} = ${msFromNum}, ` +
`BigInt version ${nsKey} = ${nsFromBigInt}n` +
` = ${msFromBigIntNs}ms`);
` = ${msFromBigIntNs}ms, Allowable delta = ${allowableDelta}`);
} else if (Number.isSafeInteger(val)) {
assert.strictEqual(
bigintStats[key], BigInt(val),
Expand All @@ -88,92 +87,102 @@ function verifyStats(bigintStats, numStats) {
);
} else {
assert(
Math.abs(Number(bigintStats[key]) - val) < 1,
Number(bigintStats[key]) - val < 1,
`${key} is not a safe integer, difference should < 1.\n` +
`Number version ${val}, BigInt version ${bigintStats[key]}n`);
}
}
}

const runSyncTest = (func, arg) => {
const startTime = process.hrtime.bigint();
const bigintStats = func(arg, { bigint: true });
const numStats = func(arg);
const endTime = process.hrtime.bigint();
const allowableDelta = Math.ceil(Number(endTime - startTime) / 1e6);
verifyStats(bigintStats, numStats, allowableDelta);
};

{
const filename = getFilename();
const bigintStats = fs.statSync(filename, { bigint: true });
const numStats = fs.statSync(filename);
verifyStats(bigintStats, numStats);
runSyncTest(fs.statSync, filename);
}

if (!common.isWindows) {
const filename = getFilename();
const link = `${filename}-link`;
fs.symlinkSync(filename, link);
const bigintStats = fs.lstatSync(link, { bigint: true });
const numStats = fs.lstatSync(link);
verifyStats(bigintStats, numStats);
runSyncTest(fs.lstatSync, link);
}

{
const filename = getFilename();
const fd = fs.openSync(filename, 'r');
const bigintStats = fs.fstatSync(fd, { bigint: true });
const numStats = fs.fstatSync(fd);
verifyStats(bigintStats, numStats);
runSyncTest(fs.fstatSync, fd);
fs.closeSync(fd);
}

const runCallbackTest = (func, arg, done) => {
const startTime = process.hrtime.bigint();
func(arg, { bigint: true }, common.mustCall((err, bigintStats) => {
func(arg, common.mustCall((err, numStats) => {
const endTime = process.hrtime.bigint();
const allowableDelta = Math.ceil(Number(endTime - startTime) / 1e6);
verifyStats(bigintStats, numStats, allowableDelta);
if (done) {
done();
}
}));
}));
};

{
const filename = getFilename();
fs.stat(filename, { bigint: true }, (err, bigintStats) => {
fs.stat(filename, (err, numStats) => {
verifyStats(bigintStats, numStats);
});
});
runCallbackTest(fs.stat, filename);
}

if (!common.isWindows) {
const filename = getFilename();
const link = `${filename}-link`;
fs.symlinkSync(filename, link);
fs.lstat(link, { bigint: true }, (err, bigintStats) => {
fs.lstat(link, (err, numStats) => {
verifyStats(bigintStats, numStats);
});
});
runCallbackTest(fs.lstat, link);
}

{
const filename = getFilename();
const fd = fs.openSync(filename, 'r');
fs.fstat(fd, { bigint: true }, (err, bigintStats) => {
fs.fstat(fd, (err, numStats) => {
verifyStats(bigintStats, numStats);
fs.closeSync(fd);
});
});
runCallbackTest(fs.fstat, fd, () => { fs.closeSync(fd); });
}

(async function() {
const runPromiseTest = async (func, arg) => {
const startTime = process.hrtime.bigint();
const bigintStats = await func(arg, { bigint: true });
const numStats = await func(arg);
const endTime = process.hrtime.bigint();
const allowableDelta = Math.ceil(Number(endTime - startTime) / 1e6);
verifyStats(bigintStats, numStats, allowableDelta);
};

{
const filename = getFilename();
const bigintStats = await promiseFs.stat(filename, { bigint: true });
const numStats = await promiseFs.stat(filename);
verifyStats(bigintStats, numStats);
})();
runPromiseTest(promiseFs.stat, filename);
}

if (!common.isWindows) {
(async function() {
const filename = getFilename();
const link = `${filename}-link`;
fs.symlinkSync(filename, link);
const bigintStats = await promiseFs.lstat(link, { bigint: true });
const numStats = await promiseFs.lstat(link);
verifyStats(bigintStats, numStats);
})();
const filename = getFilename();
const link = `${filename}-link`;
fs.symlinkSync(filename, link);
runPromiseTest(promiseFs.lstat, link);
}

(async function() {
const filename = getFilename();
const handle = await promiseFs.open(filename, 'r');
const startTime = process.hrtime.bigint();
const bigintStats = await handle.stat({ bigint: true });
const numStats = await handle.stat();
verifyStats(bigintStats, numStats);
const endTime = process.hrtime.bigint();
const allowableDelta = Math.ceil(Number(endTime - startTime) / 1e6);
verifyStats(bigintStats, numStats, allowableDelta);
await handle.close();
})();