Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix unreliable test-fs-stat-bigint #21949

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
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
47 changes: 32 additions & 15 deletions test/parallel/test-fs-stat-bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ const { isDate } = require('util').types;

tmpdir.refresh();

const fn = path.join(tmpdir.path, 'test-file');
fs.writeFileSync(fn, 'test');
let testIndex = 0;

let link;
if (!common.isWindows) {
link = path.join(tmpdir.path, 'symbolic-link');
fs.symlinkSync(fn, link);
function getFilename() {
const filename = path.join(tmpdir.path, `test-file-${++testIndex}`);
fs.writeFileSync(filename, 'test');
return filename;
}

function linkToFile(filename) {
const link = path.join(tmpdir.path, `symbolic-link-${testIndex}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this maybe also increment the index?

Copy link
Member

@Trott Trott Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wouldn't hurt but also isn't necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe another fun option might be to change it from:

`symbolic-link-${testIndex}`

...to:

`${filename}-link`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...which might make the whole function unnecessary? All calls to the function could be replaced with:

fs.symlinkSync(filename, `${filename}-link`);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorporated the changes you suggested. I still have the link variable in there to keep the line width under limit.

fs.symlinkSync(filename, link);
return link;
}

function verifyStats(bigintStats, numStats) {
Expand Down Expand Up @@ -74,34 +79,41 @@ function verifyStats(bigintStats, numStats) {
}

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

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

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

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

if (!common.isWindows) {
const filename = getFilename();
const link = linkToFile(filename);
fs.lstat(link, { bigint: true }, (err, bigintStats) => {
fs.lstat(link, (err, numStats) => {
verifyStats(bigintStats, numStats);
Expand All @@ -110,7 +122,8 @@ if (!common.isWindows) {
}

{
const fd = fs.openSync(fn, 'r');
const filename = getFilename();
const fd = fs.openSync(filename, 'r');
fs.fstat(fd, { bigint: true }, (err, bigintStats) => {
fs.fstat(fd, (err, numStats) => {
verifyStats(bigintStats, numStats);
Expand All @@ -120,21 +133,25 @@ if (!common.isWindows) {
}

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

if (!common.isWindows) {
(async function() {
const filename = getFilename();
const link = linkToFile(filename);
const bigintStats = await promiseFs.lstat(link, { bigint: true });
const numStats = await promiseFs.lstat(link);
verifyStats(bigintStats, numStats);
})();
}

(async function() {
const handle = await promiseFs.open(fn, 'r');
const filename = getFilename();
const handle = await promiseFs.open(filename, 'r');
const bigintStats = await handle.stat({ bigint: true });
const numStats = await handle.stat();
verifyStats(bigintStats, numStats);
Expand Down