Skip to content

test: avoid intermittent failure of test.watcher.js#3695

Open
Rob--W wants to merge 1 commit intomozilla:masterfrom
Rob--W:test-watcher-fix-intermittent
Open

test: avoid intermittent failure of test.watcher.js#3695
Rob--W wants to merge 1 commit intomozilla:masterfrom
Rob--W:test-watcher-fix-intermittent

Conversation

@Rob--W
Copy link
Copy Markdown
Member

@Rob--W Rob--W commented Apr 25, 2026

The "changes if the watched file is touched" test failed frequently when I ran it, due to the file change not having been detected. This is because the whenFilesChanged promise has not resolved when the hardcode test timeout of 500 ms was reached.

Bumping that 500 to 1000 solves the issue.

The "does not change if watched file is not touched" test is directly impacted by this timeout change, because it waits for that time before checking the result. To avoid this, schedule the setup of that test earlier, so that it runs in parallel with the other test.

Before (2 seconds and intermittent failures):

    ✔ watches for changes in the sourceDir (1065ms)
    --watch-file option is passed in
      ✔ changes if the watched file is touched (514ms)
      ✔ does not change if watched file is not touched (514ms)

After (2 seconds and no intermittent failure):

  watcher
    ✔ watches for changes in the sourceDir (1078ms)
    --watch-file option is passed in
      ✔ does not change if watched file is not touched (setup)
      ✔ changes if the watched file is touched (519ms)
      ✔ does not change if watched file is not touched (await) (498ms)

(without the parallelization trick, it would have taken 2.5 seconds)

The "changes if the watched file is touched" test failed frequently when
I ran it, due to the file change not having been detected. This is
because the `whenFilesChanged` promise has not resolved when the
hardcode test timeout of 500 ms was reached.

Bumping that 500 to 1000 solves the issue.

The "does not change if watched file is not touched" test is directly
impacted by this timeout change, because it waits for that time before
checking the result. To avoid this, schedule the setup of that test
earlier, so that it runs in parallel with the other test.

Before (2 seconds and intermittent failures):

```
    ✔ watches for changes in the sourceDir (1065ms)
    --watch-file option is passed in
      ✔ changes if the watched file is touched (514ms)
      ✔ does not change if watched file is not touched (514ms)
```

After (2 seconds and no intermittent failure):

```
  watcher
    ✔ watches for changes in the sourceDir (1078ms)
    --watch-file option is passed in
      ✔ does not change if watched file is not touched (setup)
      ✔ changes if the watched file is touched (519ms)
      ✔ does not change if watched file is not touched (await) (498ms)
```

(without the parallelization trick, it would have taken 2.5 seconds)
@Rob--W Rob--W requested a review from rpl April 25, 2026 18:29
resolve(assertParams);
}, 500),
),
new Promise((resolve) => setTimeout(resolve, 1000)),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 500 to 1000 change was the only necessary change of this whole code block here. However, I moved the old code around a little bit to increase the readability (making it obvious that whenFilesChanged is racing against a timer and that everything else is identical).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant