GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: deflake async-hooks statwatcher test · nodejs/node@503bee4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/async-hooks
    • test-statwatcher.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/async-hooks/test-statwatcher.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-statwatcher.js
+29-4Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,32 @@ checkInvocations(statwatcher1, { init: 1 },
5959
'watcher1: when started to watch second file');
6060
checkWatcherStart('watcher2', statwatcher2);
6161

62-
setTimeout(() => fs.writeFileSync(file1, 'foo++'),
63-
common.platformTimeout(100));
62+
let w2Initialized = false;
63+
let writeFile2AfterW1 = false;
64+
65+
const onW2Initialized = (curr, prev) => {
66+
if (curr.nlink !== 0 || prev.nlink !== 0)
67+
return;
68+
69+
w2.removeListener('change', onW2Initialized);
70+
w2Initialized = true;
71+
if (writeFile2AfterW1) {
72+
setTimeout(() => fs.writeFileSync(file2, 'bar++'),
73+
common.platformTimeout(100));
74+
}
75+
};
76+
w2.on('change', onW2Initialized);
77+
6478
w1.on('change', common.mustCallAtLeast((curr, prev) => {
6579
console.log('w1 change to', curr, 'from', prev);
80+
// Wait for the initial ENOENT poll before creating the file. Otherwise the
81+
// first stat can race with the write and use the created file as the baseline.
82+
if (curr.nlink === 0 && prev.nlink === 0) {
83+
setTimeout(() => fs.writeFileSync(file1, 'foo++'),
84+
common.platformTimeout(100));
85+
return;
86+
}
87+
6688
// Wait until we get the write above.
6789
if (prev.size !== 0 || curr.size !== 5)
6890
return;
@@ -74,8 +96,11 @@ w1.on('change', common.mustCallAtLeast((curr, prev) => {
7496
checkInvocations(statwatcher2, { init: 1 },
7597
'watcher2: when unwatched first file');
7698

77-
setTimeout(() => fs.writeFileSync(file2, 'bar++'),
78-
common.platformTimeout(100));
99+
writeFile2AfterW1 = true;
100+
if (w2Initialized) {
101+
setTimeout(() => fs.writeFileSync(file2, 'bar++'),
102+
common.platformTimeout(100));
103+
}
79104
w2.on('change', common.mustCallAtLeast((curr, prev) => {
80105
console.log('w2 change to', curr, 'from', prev);
81106
// Wait until we get the write above.

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.