Skip to content
Permalink
Browse files

test: fix unreliable test-fs-stat-bigint

Remove side-effects between testcases by creating a new file everytime.

Fixes: #21948
PR-URL: #21949
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information...
sagulati authored and Trott committed Jul 23, 2018
1 parent 838001d commit 4d94bb2b1f72b6b612983a517a39c5545724a3ad
Showing with 29 additions and 15 deletions.
  1. +29 −15 test/parallel/test-fs-stat-bigint.js
@@ -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) {
@@ -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);
@@ -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);
@@ -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);

0 comments on commit 4d94bb2

Please sign in to comment.
You can’t perform that action at this time.