mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
test: deflake async-hooks statwatcher test
Wait for the initial missing-file poll before writing watched files. Otherwise uv_fs_poll can observe the created file as its baseline and never emit the expected change event. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 PR-URL: https://github.com/nodejs/node/pull/63396 Refs: https://github.com/nodejs/reliability/blob/main/reports/2026-05-15.md#jstest-failure Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
cccc7c32d8
commit
503bee4b43
1 file changed
+29
-4
@@ -59,10 +59,32 @@ checkInvocations(statwatcher1, { init: 1 },
|
||||
'watcher1: when started to watch second file');
|
||||
checkWatcherStart('watcher2', statwatcher2);
|
||||
|
||||
setTimeout(() => fs.writeFileSync(file1, 'foo++'),
|
||||
common.platformTimeout(100));
|
||||
let w2Initialized = false;
|
||||
let writeFile2AfterW1 = false;
|
||||
|
||||
const onW2Initialized = (curr, prev) => {
|
||||
if (curr.nlink !== 0 || prev.nlink !== 0)
|
||||
return;
|
||||
|
||||
w2.removeListener('change', onW2Initialized);
|
||||
w2Initialized = true;
|
||||
if (writeFile2AfterW1) {
|
||||
setTimeout(() => fs.writeFileSync(file2, 'bar++'),
|
||||
common.platformTimeout(100));
|
||||
}
|
||||
};
|
||||
w2.on('change', onW2Initialized);
|
||||
|
||||
w1.on('change', common.mustCallAtLeast((curr, prev) => {
|
||||
console.log('w1 change to', curr, 'from', prev);
|
||||
// Wait for the initial ENOENT poll before creating the file. Otherwise the
|
||||
// first stat can race with the write and use the created file as the baseline.
|
||||
if (curr.nlink === 0 && prev.nlink === 0) {
|
||||
setTimeout(() => fs.writeFileSync(file1, 'foo++'),
|
||||
common.platformTimeout(100));
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait until we get the write above.
|
||||
if (prev.size !== 0 || curr.size !== 5)
|
||||
return;
|
||||
@@ -74,8 +96,11 @@ w1.on('change', common.mustCallAtLeast((curr, prev) => {
|
||||
checkInvocations(statwatcher2, { init: 1 },
|
||||
'watcher2: when unwatched first file');
|
||||
|
||||
setTimeout(() => fs.writeFileSync(file2, 'bar++'),
|
||||
common.platformTimeout(100));
|
||||
writeFile2AfterW1 = true;
|
||||
if (w2Initialized) {
|
||||
setTimeout(() => fs.writeFileSync(file2, 'bar++'),
|
||||
common.platformTimeout(100));
|
||||
}
|
||||
w2.on('change', common.mustCallAtLeast((curr, prev) => {
|
||||
console.log('w2 change to', curr, 'from', prev);
|
||||
// Wait until we get the write above.
|
||||
|
||||
Reference in new issue
Block a user