Skip to content

Make FileSystemWatcher multi-move tests order-insensitive only where the OS reorders events - #137557

Merged
lewing merged 1 commit into
dotnet:mainfrom
lewing:lewing-fix-test-ordering-constraints
Nov 16, 2026
Merged

lewing merged 1 commit into
dotnet:mainfrom
lewing:lewing-fix-test-ordering-constraints

Conversation

@lewing

@lewing lewing commented Nov 14, 2026

Copy link
Copy Markdown
Member

macOS FSEvents can deliver events for different paths out of order (e.g. Deleted file1, file0, file2 after moving file0..file2), which makes the multi-file/directory move tests fail their order-sensitive Assert.Equal. OpenBSD's libinotify has the same limitation, which is why one of these tests was skipped there.

Event order isn't part of FileSystemWatcher's documented contract, but Windows and Linux inotify do deliver events in order, and the Linux implementation's deferred IN_MOVED_FROM → Deleted handling is exactly what these tests exercise, so the strict check is kept where the OS preserves order.

Changes

  • Add PlatformDetection.IsFileSystemWatcherEventOrderPreserved (false on macOS, MacCatalyst, OpenBSD).
  • Add FileSystemWatcherTest.AssertEventsEqual, which compares as a multiset (counts and duplicates still checked) when order isn't preserved, and strictly otherwise.
  • Use it in FileMove_Multiple_FromWatchedToUnwatched, FileMove_Multiple_FromUnwatchedToWatched, DirectoryMove_Multiple_FromWatchedToUnwatched and DirectoryMove_Multiple_FromUnwatchedToWatched.
  • Re-enable Directory_Move_Multiple_From_Watched_To_Unwatched_Mac (disabled for the same reordering under System.IO.Tests.Directory_Move_Tests.Directory_Move_Multiple_From_Watched_To_Unwatched_Mac #127651).
  • Re-enable File_Move_Multiple_From_Unwatched_To_WatchedMac on OpenBSD (skipped only for ordering).

Validation

  • ./build.sh clr+libs -rc release — succeeded.
  • ./dotnet.sh build src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj /t:Test -f net12.0-osx "/p:XUnitOptions=-class System.IO.Tests.File_Move_Tests -class System.IO.Tests.Directory_Move_Tests" on osx-arm64 — passed (Total: 28, Failed: 0, Skipped: 0), including all 12 *Multiple* cases.

The reordering is intermittent, so a local pass doesn't prove the flake is gone. OpenBSD was not tested.

Fixes #127651

Resolves #137556

Note

This PR description was generated with the assistance of GitHub Copilot.

…s events

macOS FSEvents (and OpenBSD libinotify) can deliver events for different
paths out of order, which made the multi-file/directory move tests flaky.
Add PlatformDetection.IsFileSystemWatcherEventOrderPreserved and a shared
AssertEventsEqual helper that compares events as a multiset on those
platforms while keeping the strict order check on Windows/Linux/FreeBSD,
where it guards e.g. the deferred IN_MOVED_FROM handling.

Re-enable Directory_Move_Multiple_From_Watched_To_Unwatched_Mac (dotnet#127651)
and File_Move_Multiple_From_Unwatched_To_WatchedMac on OpenBSD.

Fixes dotnet#137556

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the platform-aware event-ordering test changes.

No open issues 🎉

What changed in this PR

This PR adjusts FileSystemWatcher multi-move tests to tolerate platform-specific event reordering while retaining strict ordering checks on Windows and Linux. It addresses ordering-related test failures without changing production behavior.

Changes:

  • Identify macOS, MacCatalyst, and OpenBSD as platforms where event order is not preserved.
  • Add a shared comparison helper that ignores order on those platforms while still checking event counts and duplicates.
  • Update four multi-move test helpers and re-enable the affected macOS and OpenBSD cases.
File Description
src/​libraries/​System.IO.FileSystem.Watcher/​tests/​Utility/​FileSystemWatcherTest.cs Adds platform-aware event comparison.
src/​libraries/​System.IO.FileSystem.Watcher/​tests/​FileSystemWatcher.File.Move.cs Updates multi-file move assertions and removes the OpenBSD skip.
src/​libraries/​System.IO.FileSystem.Watcher/​tests/​FileSystemWatcher.Directory.Move.cs Updates multi-directory move assertions and re-enables the macOS test.
src/​libraries/​Common/​tests/​TestUtilities/​System/​PlatformDetection.cs Adds the event-order preservation predicate.

Review effort: Balanced

@lewing
lewing merged commit b7bc828 into dotnet:main Nov 16, 2026
67 checks passed
lewing added a commit that referenced this pull request Nov 17, 2026
…137688)

Fixes Issue <!-- Issue Number -->
Test-only backport for the event-ordering failures tracked by #127651
and #137556.

main PR <!-- Link to PR if any that fixed this in the main branch. -->
#137557

# Description

<!-- Give a brief summary of the issue and how the pull request is
fixing it. -->

Adapt the test-only portions of b7bc828
to `release/10.0`.

The four multi-file/directory move assertions use a shared
`AssertEventsEqual` helper. On macOS and MacCatalyst, it compares events
as a multiset, preserving event identity, total counts, and duplicate
counts. Windows and Linux retain strict ordering.

This branch has no `PlatformDetection.IsOpenBSD`, and the source PR's
platform skips to remove are already absent. Those portions are omitted.
Existing unrelated platform skips and event filtering are preserved, and
no main-only deduplication infrastructure is imported.

All changes are confined to the four test/test-utility files. No product
code or public API changes.

# Customer Impact

<!-- What is the impact to customers of not taking this fix? -->

No direct customer impact. This reduces intermittent FileSystemWatcher
CI failures caused by macOS delivering events for different paths out of
order.

# Regression

<!-- Is this fixing a problem that was introduced in the most recent
release, ie., fixing a regression? -->

No product regression. The tests incorrectly assumed cross-path event
ordering on macOS.

# Testing

<!-- What kind of testing has been done with the fix. -->

On macOS arm64:

- `./build.sh clr+libs -rc release` on local `main` at
a56ab6e before applying the backport:
passed, with 18 existing dependency-vulnerability warnings and no
errors. This was not a `release/10.0` baseline build.
- `./dotnet.sh build
src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj
-f net10.0-osx /p:UseLocalTargetingRuntimePack=false`: passed, no
warnings or errors.
- `./dotnet.sh build src/tasks/installer.tasks/installer.tasks.csproj`:
passed, no warnings or errors; supplies the branch's test-runner
generation task.
- `./dotnet.sh build
src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj
/t:Test -f net10.0-osx /p:UseLocalTargetingRuntimePack=false
"/p:NetCoreAppCurrentTestHostPath=$PWD/.dotnet/" "/p:XUnitOptions=-class
System.IO.Tests.File_Move_Tests -class
System.IO.Tests.Directory_Move_Tests"`: passed against the official .NET
10.0.15 runtime bundled with SDK 10.0.115, not the locally built main
runtime. XML results confirm 27 passed, 0 failed, 0 skipped, including
all 12 applicable multi-move cases.
- A temporary, uncommitted reflection probe invoked the compiled
assertion helper: all six checks passed (reordered duplicates accepted;
unequal duplicate multiplicities, missing events, extra events, changed
event types, and changed paths rejected).
- `git diff --check`: passed.

The initial SDK extraction hit a disk-space error; after removing this
session's disposable baseline build intermediates, SDK installation and
the targeted build succeeded. The first test invocation lacked the
branch's runner-generation task; building `installer.tasks` resolved it.

No full `release/10.0` product build, full FileSystemWatcher suite,
Windows/Linux/MacCatalyst execution, or PR CI run was performed. Event
reordering is intermittent, so a passing local run alone does not
establish that the flake is eliminated.

# Risk

<!-- Please assess the risk of taking this fix. Provide details backing
up your assessment. -->

Low risk: test-only changes, with no shipped product or API changes.
Only the four multi-move assertions change. On platforms that reorder
events, comparison still rejects missing, extra, or different events,
including differing duplicate counts. Strict ordering remains on
Windows/Linux, and existing platform skips and filters are unchanged.

# Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet
package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older
versions.

> [!NOTE]
> This PR description was generated with GitHub Copilot.

Co-authored-by: Copilot App <[email protected]>
lewing added a commit that referenced this pull request Nov 17, 2026
…137686)

Fixes Issue <!-- Issue Number -->
Addresses the test failures tracked by
#127651 and
#137556 on release/11.0.

main PR <!-- Link to PR if any that fixed this in the main branch. -->
#137557

# Description

<!-- Give a brief summary of the issue and how the pull request is
fixing it. -->

Test-only, whole backport of b7bc828,
applied without adaptation.

FileSystemWatcher events for different paths can arrive out of order on
macOS, MacCatalyst, and OpenBSD. Add the shared platform predicate and
event-comparison helper, and update the four multi-move test helpers to
compare events as a multiset on those platforms, retaining duplicate
counts. Preserve strict event ordering elsewhere, including Windows and
Linux.

Re-enable the macOS directory multi-move test and the OpenBSD file
multi-move test previously disabled for event ordering. All four source
files are included; no product code changes.

# Customer Impact

<!-- What is the impact to customers of not taking this fix? -->

No product or public API impact. Without this fix, ordering-related test
failures and disabled test coverage remain on the servicing branch.

# Regression

<!-- Is this fixing a problem that was introduced in the most recent
release, ie., fixing a regression? -->

Not a product regression fix. Corrects existing platform-specific test
assumptions and restores test coverage.

# Testing

<!-- What kind of testing has been done with the fix. -->

- On macOS arm64, `./build.sh clr+libs -rc release` succeeded with 0
warnings and 0 errors.
- Built and ran both affected move-test classes against the locally
built release/11.0 runtime/libraries:

  ```sh
./dotnet.sh build
src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj
/t:Test -f net11.0-osx "/p:XUnitOptions=-class
System.IO.Tests.File_Move_Tests -class
System.IO.Tests.Directory_Move_Tests"
  ```

- Passed: 28 tests, 0 failures, 0 skips, including all 12 multi-move
cases and the re-enabled macOS directory test. Test-result XML confirms
these counts.
- The applied patch has the same stable patch ID as the source commit;
no branch-specific adaptations. `git diff --check` passed.
- Windows, Linux, MacCatalyst, and OpenBSD were not run locally, nor was
the complete FileSystemWatcher suite. Event reordering is intermittent;
one local pass does not prove the flake cannot recur.

# Risk

<!-- Please assess the risk of taking this fix. Provide details backing
up your assessment. -->

Low risk: changes only tests and shared test utilities. Event types,
paths, total counts, and duplicate multiplicities remain checked. Strict
ordering is retained where the OS preserves it. No shipping binaries or
public APIs are changed.

# Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet
package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older
versions.

N/A: test-only change; no package authoring is required.

> [!NOTE]
> This PR description was generated with the assistance of GitHub
Copilot.

Co-authored-by: Copilot App <[email protected]>
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants