-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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-fs-watch-recursive-add-* tests fail intermittently on macOS #55592
Comments
Take |
I also reported it on Slack: https://openjs-foundation.slack.com/archives/C019Y2T6STH/p1728922765557729 @santigimeno Suggested to try this patch (I didn't have the time to test it): diff --git a/test/parallel/test-fs-watch-recursive-add-file.js b/test/parallel/test-fs-watch-recursive-add-file.js
index 27b933871c..68c17890fc 100644
--- a/test/parallel/test-fs-watch-recursive-add-file.js
+++ b/test/parallel/test-fs-watch-recursive-add-file.js
@@ -28,22 +28,32 @@ fs.mkdirSync(testDirectory);
const testFile = path.join(testDirectory, 'file-1.txt');
-const watcher = fs.watch(testDirectory, { recursive: true });
-let watcherClosed = false;
-watcher.on('change', function(event, filename) {
- assert.strictEqual(event, 'rename');
-
- if (filename === path.basename(testFile)) {
- watcher.close();
- watcherClosed = true;
- }
-});
-
-// Do the write with a delay to ensure that the OS is ready to notify us.
-setTimeout(() => {
- fs.writeFileSync(testFile, 'world');
-}, common.platformTimeout(200));
-
-process.once('exit', function() {
- assert(watcherClosed, 'watcher Object was not closed');
-});
+function doWatch() {
+ const watcher = fs.watch(testDirectory, { recursive: true });
+ let watcherClosed = false;
+ watcher.on('change', function(event, filename) {
+ assert.strictEqual(event, 'rename');
+
+ if (filename === path.basename(testFile)) {
+ watcher.close();
+ watcherClosed = true;
+ }
+ });
+
+ // Do the write with a delay to ensure that the OS is ready to notify us.
+ setTimeout(() => {
+ fs.writeFileSync(testFile, 'world');
+ }, common.platformTimeout(200));
+
+ process.once('exit', function() {
+ assert(watcherClosed, 'watcher Object was not closed');
+ });
+}
+
+if (common.isMacOS) {
+ // On macOS delay watcher start to avoid leaking previous events.
+ // Refs: https://github.com/libuv/libuv/pull/4503
+ setTimeout(doWatch, common.platformTimeout(100));
+} else {
+ doWatch();
+} |
If it's working as expected and it's the test that needs to be fixed, #55592 (comment) still doesn't seem very reliable with the 200 timeout, it could just be adjusted to tolerate that change event emitted for the directory instead of only expecting one single rename event emitted for the changed file. |
I am not sure exactly when but at least since this week I am seeing intermittent failures of
test-fs-watch-recursive-add-*
tests on the main branch. Trying to run with-j1
or simply re-running them directly doesn't seem to make a difference either.The text was updated successfully, but these errors were encountered: