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: https://github.com/nodejs/node/pull/51842
Refs: https://github.com/nodejs/reliability/issues/790
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Joyee Cheung committed 2024-02-25 07:21:50 +01:00
1 parent ec7a2680b2
commit 7f3852c376
6 files changed
+27 -7

No files matched your search

@@ -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');
@@ -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');
@@ -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');
@@ -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());
@@ -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));
@@ -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));