Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c0918f0

Browse filesBrowse 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 <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 1f6551d commit c0918f0
Copy full SHA for c0918f0
Expand file treeCollapse file tree

6 files changed

+27
-7
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-add-file-to-existing-subfolder.js
+4-1Lines changed: 4 additions & 1 deletion
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');
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-add-file-to-new-folder.js
+5-2Lines changed: 5 additions & 2 deletions
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');
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-add-file.js
+4-1Lines changed: 4 additions & 1 deletion
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');
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-assert-leaks.js
+6-1Lines changed: 6 additions & 1 deletion
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());
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-sync-write.js
+4-1Lines changed: 4 additions & 1 deletion
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));
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-update-file.js
+4-1Lines changed: 4 additions & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.