Skip to content

Commit 17b92f0

Browse files
bnoordhuistargos
authored andcommitted
test: use unique file names in fs trace test
Should fix test flakiness that is presumably caused by the asynchronous nature of the unlink operation on Windows. It's been observed that sub-tests randomly fail with "permission denied" errors when trying to create a new file in a directory with appropriate permissions. The DeleteFile() NT API call makes a file inaccessible and marks it for deletion but doesn't actually delete it until the last open handle has been closed. Accessing such a file fails with ERROR_ACCESS_DENIED. Processes can close handles manually or wait for the operating system to close them asynchronously after process termination. I speculate it's the latter that's causing the test to turn flaky. Fixes: #43502 PR-URL: #43504 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 60b949d commit 17b92f0

File tree

1 file changed

+84
-84
lines changed

1 file changed

+84
-84
lines changed

test/parallel/test-trace-events-fs-sync.js

+84-84
Original file line numberDiff line numberDiff line change
@@ -16,102 +16,102 @@ if (!common.isWindows) {
1616
uid = process.getuid();
1717
}
1818

19-
tests['fs.sync.access'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
20-
'fs.accessSync("fs.txt");' +
21-
'fs.unlinkSync("fs.txt")';
22-
tests['fs.sync.chmod'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
23-
'fs.chmodSync("fs.txt",100);' +
24-
'fs.unlinkSync("fs.txt")';
25-
tests['fs.sync.chown'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
26-
`fs.chownSync("fs.txt", ${uid}, ${gid});` +
27-
'fs.unlinkSync("fs.txt")';
28-
tests['fs.sync.close'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
29-
'fs.unlinkSync("fs.txt")';
30-
tests['fs.sync.copyfile'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
31-
'fs.copyFileSync("fs.txt","a.txt");' +
32-
'fs.unlinkSync("fs.txt")';
33-
tests['fs.sync.fchmod'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
34-
'const fd = fs.openSync("fs.txt", "r+");' +
19+
tests['fs.sync.access'] = 'fs.writeFileSync("fs0.txt", "123", "utf8");' +
20+
'fs.accessSync("fs0.txt");' +
21+
'fs.unlinkSync("fs0.txt")';
22+
tests['fs.sync.chmod'] = 'fs.writeFileSync("fs1.txt", "123", "utf8");' +
23+
'fs.chmodSync("fs1.txt",100);' +
24+
'fs.unlinkSync("fs1.txt")';
25+
tests['fs.sync.chown'] = 'fs.writeFileSync("fs2.txt", "123", "utf8");' +
26+
`fs.chownSync("fs2.txt", ${uid}, ${gid});` +
27+
'fs.unlinkSync("fs2.txt")';
28+
tests['fs.sync.close'] = 'fs.writeFileSync("fs3.txt", "123", "utf8");' +
29+
'fs.unlinkSync("fs3.txt")';
30+
tests['fs.sync.copyfile'] = 'fs.writeFileSync("fs4.txt", "123", "utf8");' +
31+
'fs.copyFileSync("fs4.txt","a.txt");' +
32+
'fs.unlinkSync("fs4.txt")';
33+
tests['fs.sync.fchmod'] = 'fs.writeFileSync("fs5.txt", "123", "utf8");' +
34+
'const fd = fs.openSync("fs5.txt", "r+");' +
3535
'fs.fchmodSync(fd,100);' +
36-
'fs.unlinkSync("fs.txt")';
37-
tests['fs.sync.fchown'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
38-
'const fd = fs.openSync("fs.txt", "r+");' +
36+
'fs.unlinkSync("fs5.txt")';
37+
tests['fs.sync.fchown'] = 'fs.writeFileSync("fs6.txt", "123", "utf8");' +
38+
'const fd = fs.openSync("fs6.txt", "r+");' +
3939
`fs.fchownSync(fd, ${uid}, ${gid});` +
40-
'fs.unlinkSync("fs.txt")';
41-
tests['fs.sync.fdatasync'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
42-
'const fd = fs.openSync("fs.txt", "r+");' +
40+
'fs.unlinkSync("fs6.txt")';
41+
tests['fs.sync.fdatasync'] = 'fs.writeFileSync("fs7.txt", "123", "utf8");' +
42+
'const fd = fs.openSync("fs7.txt", "r+");' +
4343
'fs.fdatasyncSync(fd);' +
44-
'fs.unlinkSync("fs.txt")';
45-
tests['fs.sync.fstat'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
46-
'fs.readFileSync("fs.txt");' +
47-
'fs.unlinkSync("fs.txt")';
48-
tests['fs.sync.fsync'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
49-
'const fd = fs.openSync("fs.txt", "r+");' +
44+
'fs.unlinkSync("fs7.txt")';
45+
tests['fs.sync.fstat'] = 'fs.writeFileSync("fs8.txt", "123", "utf8");' +
46+
'fs.readFileSync("fs8.txt");' +
47+
'fs.unlinkSync("fs8.txt")';
48+
tests['fs.sync.fsync'] = 'fs.writeFileSync("fs9.txt", "123", "utf8");' +
49+
'const fd = fs.openSync("fs9.txt", "r+");' +
5050
'fs.fsyncSync(fd);' +
51-
'fs.unlinkSync("fs.txt")';
52-
tests['fs.sync.ftruncate'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
53-
'const fd = fs.openSync("fs.txt", "r+");' +
51+
'fs.unlinkSync("fs9.txt")';
52+
tests['fs.sync.ftruncate'] = 'fs.writeFileSync("fs10.txt", "123", "utf8");' +
53+
'const fd = fs.openSync("fs10.txt", "r+");' +
5454
'fs.ftruncateSync(fd, 1);' +
55-
'fs.unlinkSync("fs.txt")';
56-
tests['fs.sync.futimes'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
57-
'const fd = fs.openSync("fs.txt", "r+");' +
55+
'fs.unlinkSync("fs10.txt")';
56+
tests['fs.sync.futimes'] = 'fs.writeFileSync("fs11.txt", "123", "utf8");' +
57+
'const fd = fs.openSync("fs11.txt", "r+");' +
5858
'fs.futimesSync(fd,1,1);' +
59-
'fs.unlinkSync("fs.txt")';
60-
tests['fs.sync.lchown'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
61-
`fs.lchownSync("fs.txt", ${uid}, ${gid});` +
62-
'fs.unlinkSync("fs.txt")';
63-
tests['fs.sync.link'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
64-
'fs.linkSync("fs.txt", "linkx");' +
65-
'fs.unlinkSync("linkx");' +
66-
'fs.unlinkSync("fs.txt")';
67-
tests['fs.sync.lstat'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
68-
'fs.lstatSync("fs.txt");' +
69-
'fs.unlinkSync("fs.txt")';
70-
tests['fs.sync.mkdir'] = 'fs.mkdirSync("fstemp");' +
71-
'fs.rmdirSync("fstemp")';
72-
tests['fs.sync.mkdtemp'] = 'const fp = fs.mkdtempSync("fstest");' +
59+
'fs.unlinkSync("fs11.txt")';
60+
tests['fs.sync.lchown'] = 'fs.writeFileSync("fs12.txt", "123", "utf8");' +
61+
`fs.lchownSync("fs12.txt", ${uid}, ${gid});` +
62+
'fs.unlinkSync("fs12.txt")';
63+
tests['fs.sync.link'] = 'fs.writeFileSync("fs13.txt", "123", "utf8");' +
64+
'fs.linkSync("fs13.txt", "fs14.txt");' +
65+
'fs.unlinkSync("fs13.txt");' +
66+
'fs.unlinkSync("fs14.txt")';
67+
tests['fs.sync.lstat'] = 'fs.writeFileSync("fs15.txt", "123", "utf8");' +
68+
'fs.lstatSync("fs15.txt");' +
69+
'fs.unlinkSync("fs15.txt")';
70+
tests['fs.sync.mkdir'] = 'fs.mkdirSync("fstemp0");' +
71+
'fs.rmdirSync("fstemp0")';
72+
tests['fs.sync.mkdtemp'] = 'const fp = fs.mkdtempSync("fstemp1");' +
7373
'fs.rmdirSync(fp)';
74-
tests['fs.sync.open'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
75-
'fs.unlinkSync("fs.txt")';
76-
tests['fs.sync.read'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
77-
'fs.readFileSync("fs.txt");' +
78-
'fs.unlinkSync("fs.txt")';
74+
tests['fs.sync.open'] = 'fs.writeFileSync("fs16.txt", "123", "utf8");' +
75+
'fs.unlinkSync("fs16.txt")';
76+
tests['fs.sync.read'] = 'fs.writeFileSync("fs17.txt", "123", "utf8");' +
77+
'fs.readFileSync("fs17.txt");' +
78+
'fs.unlinkSync("fs17.txt")';
7979
tests['fs.sync.readdir'] = 'fs.readdirSync("./")';
80-
tests['fs.sync.realpath'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
81-
'fs.linkSync("fs.txt", "linkx");' +
82-
'fs.realpathSync.native("linkx");' +
83-
'fs.unlinkSync("linkx");' +
84-
'fs.unlinkSync("fs.txt")';
85-
tests['fs.sync.rename'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
86-
'fs.renameSync("fs.txt","xyz.txt"); ' +
87-
'fs.unlinkSync("xyz.txt")';
88-
tests['fs.sync.rmdir'] = 'fs.mkdirSync("fstemp");' +
89-
'fs.rmdirSync("fstemp")';
90-
tests['fs.sync.stat'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
91-
'fs.statSync("fs.txt");' +
92-
'fs.unlinkSync("fs.txt")';
93-
tests['fs.sync.unlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
94-
'fs.linkSync("fs.txt", "linkx");' +
95-
'fs.unlinkSync("linkx");' +
96-
'fs.unlinkSync("fs.txt")';
97-
tests['fs.sync.utimes'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
98-
'fs.utimesSync("fs.txt",1,1);' +
99-
'fs.unlinkSync("fs.txt")';
100-
tests['fs.sync.write'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
101-
'fs.unlinkSync("fs.txt")';
80+
tests['fs.sync.realpath'] = 'fs.writeFileSync("fs18.txt", "123", "utf8");' +
81+
'fs.linkSync("fs18.txt", "fs19.txt");' +
82+
'fs.realpathSync.native("fs19.txt");' +
83+
'fs.unlinkSync("fs18.txt");' +
84+
'fs.unlinkSync("fs19.txt")';
85+
tests['fs.sync.rename'] = 'fs.writeFileSync("fs20.txt", "123", "utf8");' +
86+
'fs.renameSync("fs20.txt","fs21.txt"); ' +
87+
'fs.unlinkSync("fs21.txt")';
88+
tests['fs.sync.rmdir'] = 'fs.mkdirSync("fstemp2");' +
89+
'fs.rmdirSync("fstemp2")';
90+
tests['fs.sync.stat'] = 'fs.writeFileSync("fs22.txt", "123", "utf8");' +
91+
'fs.statSync("fs22.txt");' +
92+
'fs.unlinkSync("fs22.txt")';
93+
tests['fs.sync.unlink'] = 'fs.writeFileSync("fs23.txt", "123", "utf8");' +
94+
'fs.linkSync("fs23.txt", "fs24.txt");' +
95+
'fs.unlinkSync("fs23.txt");' +
96+
'fs.unlinkSync("fs24.txt")';
97+
tests['fs.sync.utimes'] = 'fs.writeFileSync("fs25.txt", "123", "utf8");' +
98+
'fs.utimesSync("fs25.txt",1,1);' +
99+
'fs.unlinkSync("fs25.txt")';
100+
tests['fs.sync.write'] = 'fs.writeFileSync("fs26.txt", "123", "utf8");' +
101+
'fs.unlinkSync("fs26.txt")';
102102

103103
// On windows, we need permissions to test symlink and readlink.
104104
// We'll only try to run these tests if we have enough privileges.
105105
if (common.canCreateSymLink()) {
106-
tests['fs.sync.symlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
107-
'fs.symlinkSync("fs.txt", "linkx");' +
108-
'fs.unlinkSync("linkx");' +
109-
'fs.unlinkSync("fs.txt")';
110-
tests['fs.sync.readlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
111-
'fs.symlinkSync("fs.txt", "linkx");' +
112-
'fs.readlinkSync("linkx");' +
113-
'fs.unlinkSync("linkx");' +
114-
'fs.unlinkSync("fs.txt")';
106+
tests['fs.sync.symlink'] = 'fs.writeFileSync("fs27.txt", "123", "utf8");' +
107+
'fs.symlinkSync("fs27.txt", "fs28.txt");' +
108+
'fs.unlinkSync("fs27.txt");' +
109+
'fs.unlinkSync("fs28.txt")';
110+
tests['fs.sync.readlink'] = 'fs.writeFileSync("fs29.txt", "123", "utf8");' +
111+
'fs.symlinkSync("fs29.txt", "fs30.txt");' +
112+
'fs.readlinkSync("fs30.txt");' +
113+
'fs.unlinkSync("fs29.txt");' +
114+
'fs.unlinkSync("fs30.txt")';
115115
}
116116

117117
const tmpdir = require('../common/tmpdir');

0 commit comments

Comments
 (0)