Skip to content

Commit 009ab4d

Browse files
lpincatargos
authored andcommitted
test: deflake fs-promises-watch
Change the contents of the file every 100 milliseconds until the watcher notices the change. This is already done in the callback based version of the test (`test-fs-watch.js`). Fixes: #37637 PR-URL: #40863 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Nitzan Uziely <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]>
1 parent 878ba91 commit 009ab4d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

test/parallel/test-fs-promises-watch.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ for (const testCase of kCases) {
4747
const content1 = Date.now() + testCase.fileName.toLowerCase().repeat(1e4);
4848
fs.writeFileSync(testCase.filePath, content1);
4949

50+
let interval;
5051
async function test() {
5152
const watcher = watch(testCase[testCase.field]);
5253
for await (const { eventType, filename } of watcher) {
54+
clearInterval(interval);
5355
assert.strictEqual(['rename', 'change'].includes(eventType), true);
5456
assert.strictEqual(filename, testCase.fileName);
5557
break;
@@ -64,10 +66,10 @@ for (const testCase of kCases) {
6466

6567
// Long content so it's actually flushed. toUpperCase so there's real change.
6668
const content2 = Date.now() + testCase.fileName.toUpperCase().repeat(1e4);
67-
setImmediate(() => {
69+
interval = setInterval(() => {
6870
fs.writeFileSync(testCase.filePath, '');
6971
fs.writeFileSync(testCase.filePath, content2);
70-
});
72+
}, 100);
7173

7274
test().then(common.mustCall());
7375
}

0 commit comments

Comments
 (0)