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 2024-02-23 03:00:42 +01:00
parent ec7a2680b2
commit 7f3852c376
No known key found for this signature in database
GPG Key ID: 92B78A53C8303B8D
6 changed files with 27 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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