Repository navigation
Conversation
…ename (#135342) ## Summary Mitigates the flaky `Microsoft.Extensions.FileProviders.PhysicalFileProviderTests.TokensFiredForNewDirectoryContentsOnRename` test on macOS. ### Root cause The test creates a real directory/subdirectory/file structure on disk, then starts a real `FileSystemWatcher`-backed `PhysicalFilesWatcher`/`PhysicalFileProvider` watch, and asserts the corresponding change tokens have not fired yet (before the test's simulated rename). On macOS, the native watcher is backed by `fseventsd`, a separate daemon that the process subscribes to asynchronously. As documented by a .NET team member investigating a related issue (#30415 (comment)): > We can get events for operations completed **before** watcher started... even if we call `sync` to flush events when watcher is started, we may [see] old events `fseventsd` did not process yet. So even though the watcher requests `kFSEventStreamEventIdSinceNow`, there is no documented guarantee it excludes events for changes made shortly before the stream starts. This occasionally causes the "new directory/subdirectory/file should not have changed yet" assertions to fail. This is architecturally specific to macOS: Windows (`ReadDirectoryChangesW`) and Linux (`inotify`) are handle/descriptor-based with no separate daemon replaying historical events. ### Why not fix it in `FileSystemWatcher`/`PhysicalFilesWatcher` instead - The macOS backend already uses the most responsive options available in the public FSEvents API (`kFSEventStreamEventIdSinceNow`, `0.0f` latency, `NoDefer`), so there isn't more headroom at that layer. - A `PhysicalFilesWatcher`-side fix (e.g. snapshotting expected state at watch-registration time and suppressing events that predate it) could close this deterministically, but it's a meaningfully more invasive change for a bug class that, in production, results in at most a spurious/redundant change notification — not a missed one or a correctness issue. That cost/benefit doesn't justify it here, so this PR only addresses the test. ### Fix The test only needs one injected event: `fileSystemWatcher.CallOnRenamed(...)`, which invokes `FileSystemWatcher.OnRenamed` directly. That method does not perform `Filter` matching itself — pattern matching against `Filter` only happens in `NotifyFileSystemEventArgs`/`NotifyRenameEventArgs`, which wrap genuine native OS events before invoking the protected `OnChanged`/`OnCreated`/`OnRenamed` methods (see `src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs`). So the test now sets `fileSystemWatcher.Filter` to a pattern that cannot match any of its (randomly generated, GUID-named) test entries before starting the watch. This deterministically suppresses any genuine native events — including delayed `fseventsd` replays of the pre-watch directory/file creation — while leaving the explicitly injected rename event unaffected, since it bypasses `Filter` entirely. This removes the need for an artificial delay or a dynamic skip, and keeps all the pre-rename assertions active and deterministic on every platform. Fixes #135283 > [!NOTE] > This PR description and change were drafted with AI (GitHub Copilot) assistance. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b2aac025-5dc1-420e-bfdf-19dd4b2f2f6f (cherry picked from commit a60b70b) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lewing
temporarily deployed
to
copilot-pat-pool
November 27, 2026 19:35 — with
GitHub Actions
Inactive
|
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. |
lewing
temporarily deployed
to
copilot-pat-pool
November 27, 2026 19:36 — with
GitHub Actions
Inactive
Contributor
|
Tagging subscribers to this area: @dotnet/area-extensions-filesystem |
3 tasks
svick
approved these changes
Nov 30, 2026
rosebyte
approved these changes
Dec 1, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes Issue #135283
main PR #135342
Description
Test-only backport of #135342:
TokensFiredForNewDirectoryContentsOnRenamefailed on osx-arm64 in #138290 CI.Customer Impact
None; test-only.
Regression
N/A; test-only.
Testing
./dotnet.sh build src/libraries/Microsoft.Extensions.FileProviders.Physical/tests/Microsoft.Extensions.FileProviders.Physical.Tests.csproj -p:TargetFramework=net11.0 -p:UseLocalTargetingRuntimePack=false --no-incremental— passed, 0 warnings and 0 errors. Tests not run.Risk
Low; test-only.
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.