Skip to content

Commit d0a8b6f

Browse files
joyeecheungmarco-ippolito
authored andcommitted
test: ensure delay in recursive fs watch tests
The recursive fs watch tests that mutate the watched folder immediately after fs.watch() returns are all flaking in the CI while the others that mutate the folder with a bit of delay aren't flaking. So this patch adds a bit of delay for the rest of the tests to deflake them. PR-URL: #51842 Refs: nodejs/reliability#790 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent cfa9e21 commit d0a8b6f

6 files changed

+27
-7
lines changed

test/parallel/test-fs-watch-recursive-add-file-to-existing-subfolder.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ watcher.on('change', function(event, filename) {
4848
}
4949
});
5050

51-
fs.writeFileSync(childrenAbsolutePath, 'world');
51+
// Do the write with a delay to ensure that the OS is ready to notify us.
52+
setTimeout(() => {
53+
fs.writeFileSync(childrenAbsolutePath, 'world');
54+
}, common.platformTimeout(200));
5255

5356
process.once('exit', function() {
5457
assert(watcherClosed, 'watcher Object was not closed');

test/parallel/test-fs-watch-recursive-add-file-to-new-folder.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ watcher.on('change', function(event, filename) {
4444
}
4545
});
4646

47-
fs.mkdirSync(filePath);
48-
fs.writeFileSync(childrenAbsolutePath, 'world');
47+
// Do the write with a delay to ensure that the OS is ready to notify us.
48+
setTimeout(() => {
49+
fs.mkdirSync(filePath);
50+
fs.writeFileSync(childrenAbsolutePath, 'world');
51+
}, common.platformTimeout(200));
4952

5053
process.once('exit', function() {
5154
assert(watcherClosed, 'watcher Object was not closed');

test/parallel/test-fs-watch-recursive-add-file.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ watcher.on('change', function(event, filename) {
3939
}
4040
});
4141

42-
fs.writeFileSync(testFile, 'world');
42+
// Do the write with a delay to ensure that the OS is ready to notify us.
43+
setTimeout(() => {
44+
fs.writeFileSync(testFile, 'world');
45+
}, common.platformTimeout(200));
4346

4447
process.once('exit', function() {
4548
assert(watcherClosed, 'watcher Object was not closed');

test/parallel/test-fs-watch-recursive-assert-leaks.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ watcher.on('change', common.mustCallAtLeast(async (event, filename) => {
4242
process.on('exit', function() {
4343
assert(watcherClosed, 'watcher Object was not closed');
4444
});
45-
fs.writeFileSync(filePath, 'content');
45+
46+
// Do the write with a delay to ensure that the OS is ready to notify us.
47+
(async () => {
48+
await setTimeout(200);
49+
fs.writeFileSync(filePath, 'content');
50+
})().then(common.mustCall());

test/parallel/test-fs-watch-recursive-sync-write.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ const watcher = watch(tmpDir, { recursive: true }, common.mustCall((eventType, _
3232
assert.strictEqual(join(tmpDir, _filename), filename);
3333
}));
3434

35-
writeFileSync(filename, 'foobar2');
35+
// Do the write with a delay to ensure that the OS is ready to notify us.
36+
setTimeout(() => {
37+
writeFileSync(filename, 'foobar2');
38+
}, common.platformTimeout(200));

test/parallel/test-fs-watch-recursive-update-file.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ watcher.on('change', common.mustCallAtLeast(function(event, filename) {
3939
}
4040
}));
4141

42-
fs.writeFileSync(testFile, 'hello');
42+
// Do the write with a delay to ensure that the OS is ready to notify us.
43+
setTimeout(() => {
44+
fs.writeFileSync(testFile, 'hello');
45+
}, common.platformTimeout(200));

0 commit comments

Comments
 (0)