Skip to content

Commit

Permalink
test: fix unreliable test-fs-stat-bigint
Browse files Browse the repository at this point in the history
Remove side-effects between testcases by creating a new file everytime.

Fixes: #21948
PR-URL: #21949
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
sagulati authored and targos committed Jul 26, 2018
1 parent 793a5bb commit af6b824
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 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,12 @@ 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 verifyStats(bigintStats, numStats) {
Expand Down Expand Up @@ -74,34 +73,43 @@ 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 = `${filename}-link`;
fs.symlinkSync(filename, link);
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 = `${filename}-link`;
fs.symlinkSync(filename, link);
fs.lstat(link, { bigint: true }, (err, bigintStats) => {
fs.lstat(link, (err, numStats) => {
verifyStats(bigintStats, numStats);
Expand All @@ -110,7 +118,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 +129,26 @@ 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 = `${filename}-link`;
fs.symlinkSync(filename, link);
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

0 comments on commit af6b824

Please sign in to comment.