Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky sequential/test-fs-watch #36249

Merged
merged 1 commit into from
Nov 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions test/sequential/test-fs-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ const testDir = tmpdir.path;

tmpdir.refresh();

// Because macOS (and possibly other operating systems) can return a watcher
// before it is actually watching, we need to repeat the operation to avoid
// a race condition.
function repeat(fn) {
setImmediate(fn);
const interval = setInterval(fn, 5000);
return interval;
}

{
const filepath = path.join(testDir, 'watch.txt');

Expand All @@ -54,12 +63,11 @@ tmpdir.refresh();
if (expectFilePath) {
assert.strictEqual(filename, 'watch.txt');
}
clearInterval(interval);
watcher.close();
}));

setImmediate(function() {
fs.writeFileSync(filepath, 'world');
});
const interval = repeat(() => { fs.writeFileSync(filepath, 'world'); });
}

{
Expand All @@ -76,12 +84,11 @@ tmpdir.refresh();
if (expectFilePath) {
assert.strictEqual(filename, 'hasOwnProperty');
}
clearInterval(interval);
watcher.close();
}));

setImmediate(function() {
fs.writeFileSync(filepathAbs, 'pardner');
});
const interval = repeat(() => { fs.writeFileSync(filepathAbs, 'pardner'); });
}

{
Expand All @@ -97,14 +104,15 @@ tmpdir.refresh();
} else {
assert.strictEqual(filename, null);
}
clearInterval(interval);
watcher.close();
}));

setImmediate(function() {
const interval = repeat(() => {
fs.rmSync(filepath, { force: true });
const fd = fs.openSync(filepath, 'w');
fs.closeSync(fd);
});

}

// https://github.com/joyent/node/issues/2293 - non-persistent watcher should
Expand Down