Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8cb306e

Browse filesBrowse files
Trottaddaleax
authored andcommitted
test: fix flaky test-watch-file
PR-URL: #34420 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Myles Borins <myles.borins@gmail.com>
1 parent ae60f50 commit 8cb306e
Copy full SHA for 8cb306e

File tree

Expand file treeCollapse file tree

1 file changed

+14
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-4
lines changed
Open diff view settings
Collapse file

‎test/pummel/test-watch-file.js‎

Copy file name to clipboardExpand all lines: test/pummel/test-watch-file.js
+14-4Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ fs.closeSync(fs.openSync(f, 'w'));
3434
let changes = 0;
3535
function watchFile() {
3636
fs.watchFile(f, (curr, prev) => {
37+
// Make sure there is at least one watch event that shows a changed mtime.
38+
if (curr.mtime <= prev.mtime) {
39+
return;
40+
}
3741
changes++;
38-
assert.notDeepStrictEqual(curr.mtime, prev.mtime);
3942
fs.unwatchFile(f);
4043
watchFile();
4144
fs.unwatchFile(f);
@@ -44,10 +47,17 @@ function watchFile() {
4447

4548
watchFile();
4649

50+
function changeFile() {
51+
const fd = fs.openSync(f, 'w+');
52+
fs.writeSync(fd, 'xyz\n');
53+
fs.closeSync(fd);
54+
}
4755

48-
const fd = fs.openSync(f, 'w+');
49-
fs.writeSync(fd, 'xyz\n');
50-
fs.closeSync(fd);
56+
changeFile();
57+
const interval = setInterval(changeFile, 1000);
58+
// Use unref() here so fs.watchFile() watcher is the only thing keeping the
59+
// event loop open.
60+
interval.unref();
5161

5262
process.on('exit', function() {
5363
assert.ok(changes > 0);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.