From 4d94bb2b1f72b6b612983a517a39c5545724a3ad Mon Sep 17 00:00:00 2001 From: sagulati Date: Mon, 23 Jul 2018 15:59:13 -0700 Subject: [PATCH] test: fix unreliable test-fs-stat-bigint Remove side-effects between testcases by creating a new file everytime. Fixes: https://github.com/nodejs/node/issues/21948 PR-URL: https://github.com/nodejs/node/pull/21949 Reviewed-By: Rich Trott Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca --- test/parallel/test-fs-stat-bigint.js | 44 ++++++++++++++++++---------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-fs-stat-bigint.js b/test/parallel/test-fs-stat-bigint.js index 943c0d55d86ba8..4691b2dd9d267e 100644 --- a/test/parallel/test-fs-stat-bigint.js +++ b/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,19 +73,24 @@ 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); @@ -94,14 +98,18 @@ if (!common.isWindows) { } { - 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,13 +129,17 @@ 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); @@ -134,7 +147,8 @@ if (!common.isWindows) { } (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);