mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
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: https://github.com/nodejs/node/issues/37637 PR-URL: https://github.com/nodejs/node/pull/40863 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Nitzan Uziely <linkgoron@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
This commit is contained in:
1 parent
b54d53b9dd
commit
9e2e4437b9
1 file changed
+4
-2
@@ -47,9 +47,11 @@ for (const testCase of kCases) {
|
||||
const content1 = Date.now() + testCase.fileName.toLowerCase().repeat(1e4);
|
||||
fs.writeFileSync(testCase.filePath, content1);
|
||||
|
||||
let interval;
|
||||
async function test() {
|
||||
const watcher = watch(testCase[testCase.field]);
|
||||
for await (const { eventType, filename } of watcher) {
|
||||
clearInterval(interval);
|
||||
assert.strictEqual(['rename', 'change'].includes(eventType), true);
|
||||
assert.strictEqual(filename, testCase.fileName);
|
||||
break;
|
||||
@@ -64,10 +66,10 @@ for (const testCase of kCases) {
|
||||
|
||||
// Long content so it's actually flushed. toUpperCase so there's real change.
|
||||
const content2 = Date.now() + testCase.fileName.toUpperCase().repeat(1e4);
|
||||
setImmediate(() => {
|
||||
interval = setInterval(() => {
|
||||
fs.writeFileSync(testCase.filePath, '');
|
||||
fs.writeFileSync(testCase.filePath, content2);
|
||||
});
|
||||
}, 100);
|
||||
|
||||
test().then(common.mustCall());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user