mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
test: deflake test-watch-mode-files_watcher
Some test cases made a single change right after creating a watcher. On macOS, libuv starts the FSEvents stream asynchronously, so that change could be missed and the test hung until it timed out. Keep making the change until the watcher reports it, as the other cases in the file already do. Refs: https://github.com/nodejs/reliability/issues/1715 Refs: https://github.com/nodejs/reliability/issues/1644 Signed-off-by: inoway46 <inoueyuya416@gmail.com> PR-URL: https://github.com/nodejs/node/pull/67298 Refs: https://github.com/nodejs/node/actions/runs/42177414954 Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
This commit is contained in:
1 parent
136ae6f518
commit
098b4788ca
1 file changed
+15
-4
@@ -37,6 +37,9 @@ describe('watch mode file watcher', () => {
|
||||
afterEach(() => watcher.clear());
|
||||
|
||||
let counter = 0;
|
||||
// A newly created watcher might not report changes right away (e.g. on
|
||||
// macOS the FSEvents stream is started asynchronously), so a single write
|
||||
// can be missed. Keep writing until a change is reported.
|
||||
function writeAndWaitForChanges(watcher, file) {
|
||||
return new Promise((resolve) => {
|
||||
const interval = setInterval(() => writeFileSync(file, `write ${counter++}`), 100);
|
||||
@@ -93,19 +96,29 @@ describe('watch mode file watcher', () => {
|
||||
['--watch', file1],
|
||||
{ stdio: ['ignore', 'pipe', 'ignore'] });
|
||||
let completeCount = 0;
|
||||
let appendInterval;
|
||||
for await (const line of createInterface(child.stdout)) {
|
||||
if (!line.startsWith('Completed running')) {
|
||||
continue;
|
||||
}
|
||||
completeCount++;
|
||||
if (completeCount === 1) {
|
||||
// The watcher of the child might not report changes yet, so keep
|
||||
// changing the file until it is reloaded. The interval is longer than
|
||||
// the default debounce of watch mode so the restart is not deferred.
|
||||
appendFileSync(file1, '\n // append 1');
|
||||
appendInterval = setInterval(() => appendFileSync(file1, '\n // append'),
|
||||
common.platformTimeout(1000));
|
||||
}
|
||||
// The file is reloaded due to file watching
|
||||
if (completeCount === 2) {
|
||||
clearInterval(appendInterval);
|
||||
child.kill();
|
||||
}
|
||||
}
|
||||
// The child might have exited before the reload.
|
||||
clearInterval(appendInterval);
|
||||
assert.strictEqual(completeCount, 2);
|
||||
});
|
||||
|
||||
it('should debounce changes', async () => {
|
||||
@@ -135,6 +148,7 @@ describe('watch mode file watcher', () => {
|
||||
watcher.filterFile(file);
|
||||
files.push(file);
|
||||
}
|
||||
await writeAndWaitForChanges(watcher, files[0]);
|
||||
|
||||
files.forEach((file) => writeFileSync(file, '1'));
|
||||
files.forEach((file) => writeFileSync(file, '2'));
|
||||
@@ -203,10 +217,7 @@ describe('watch mode file watcher', () => {
|
||||
const file = tmpdir.resolve('file5');
|
||||
watcher.watchPath(tmpdir.path);
|
||||
|
||||
const changed = once(watcher, 'changed');
|
||||
await setTimeout(common.platformTimeout(100)); // avoid throttling
|
||||
writeFileSync(file, 'changed');
|
||||
await changed;
|
||||
await writeAndWaitForChanges(watcher, file);
|
||||
assert.strictEqual(changesCount, 1);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user