Skip to content

Commit

Permalink
test: ensure delay in recursive fs watch tests
Browse files Browse the repository at this point in the history
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 <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
joyeecheung authored and marco-ippolito committed Feb 26, 2024
1 parent 01d4f57 commit bb98508
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ watcher.on('change', function(event, filename) {
}
});

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

process.once('exit', function() {
assert(watcherClosed, 'watcher Object was not closed');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ watcher.on('change', function(event, filename) {
}
});

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

process.once('exit', function() {
assert(watcherClosed, 'watcher Object was not closed');
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-fs-watch-recursive-add-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ watcher.on('change', function(event, filename) {
}
});

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

process.once('exit', function() {
assert(watcherClosed, 'watcher Object was not closed');
Expand Down
7 changes: 6 additions & 1 deletion test/parallel/test-fs-watch-recursive-assert-leaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ watcher.on('change', common.mustCallAtLeast(async (event, filename) => {
process.on('exit', function() {
assert(watcherClosed, 'watcher Object was not closed');
});
fs.writeFileSync(filePath, 'content');

// Do the write with a delay to ensure that the OS is ready to notify us.
(async () => {
await setTimeout(200);
fs.writeFileSync(filePath, 'content');
})().then(common.mustCall());
5 changes: 4 additions & 1 deletion test/parallel/test-fs-watch-recursive-sync-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ const watcher = watch(tmpDir, { recursive: true }, common.mustCall((eventType, _
assert.strictEqual(join(tmpDir, _filename), filename);
}));

writeFileSync(filename, 'foobar2');
// Do the write with a delay to ensure that the OS is ready to notify us.
setTimeout(() => {
writeFileSync(filename, 'foobar2');
}, common.platformTimeout(200));
5 changes: 4 additions & 1 deletion test/parallel/test-fs-watch-recursive-update-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ watcher.on('change', common.mustCallAtLeast(function(event, filename) {
}
}));

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

0 comments on commit bb98508

Please sign in to comment.