Skip to content

Fix flaky FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories test#125682

Open
Copilot wants to merge 4 commits intomainfrom
copilot/fix-filesystemwatcher-symlink-issue
Open

Fix flaky FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories test#125682
Copilot wants to merge 4 commits intomainfrom
copilot/fix-filesystemwatcher-symlink-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

Description

FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories was consistently flaky on macOS, failing with AggregateException: (Expected Event occurred) × 3 from the ExpectNoEvent assertion.

Root cause: macOS FSEvents can deliver a late Created event for subDir (created during test setup, just before the stream starts at kFSEventStreamEventIdSinceNow). Since subDir is a direct child of the watched path, it correctly passes CheckIfPathIsNested even with IncludeSubdirectories = false. With no expectedPath filter on ExpectNoEvent, any Created event triggered the failure—including this unrelated one.

Changes:

  • ExpectNoEvent — add path filter: Pass expectedPath: Path.Combine(linkPath, subDir, subDirLv2) so the assertion only fails if a Created event fires at the specific nested path under test. Spurious events at sibling paths (e.g. subDir itself) are ignored.
  • [ActiveIssue] — removed: The [ActiveIssue] attribute has been removed entirely. The expectedPath fix makes the test robust enough to run on all platforms without skipping.
  • Comments — added disk-layout diagram and inline path annotations: A layout comment explains the relationship between tempDir, tempSubDir, linkPath, and subDirLv2Path. Each path variable and expectedPath argument is annotated with its concrete resolved value (e.g. // linkPath/subDir/subDirLv2) to make the test easier to follow.

Security

No security-relevant changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories failed with missed event</issue_title>
<issue_description>## Build Information
Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=1302001
Build error leg or test failing: System.IO.Tests.SymbolicLink_Changed_Tests.FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories
Pull request: #124628

Error Message

Fill the error message using step by step known issues guidance.

{
  "ErrorMessage": "System.AggregateException : One or more errors occurred. (Expected Event occurred) (Expected Event occurred) (Expected Event occurred)",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=1302001
Error message validated: [One or more errors occurred]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 2/20/2026 8:56:47 PM UTC

Report

Build Definition Test Pull Request
1302819 dotnet/runtime System.IO.Tests.SymbolicLink_Changed_Tests.FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories #124660
1302001 dotnet/runtime System.IO.Tests.SymbolicLink_Changed_Tests.FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories #124628

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
2 2 2

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=1302001
Error message validated: [System.AggregateException : One or more errors occurred. (Expected Event occurred) (Expected Event occurred) (Expected Event occurred)]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 2/20/2026 11:20:21 PM UTC

Report

Build Definition Test Pull Request
1302819 dotnet/runtime System.IO.Tests.SymbolicLink_Changed_Tests.FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories #124660
1302001 dotnet/runtime System.IO.Tests.SymbolicLink_Changed_Tests.FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories #124628

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
2 2 2

Report

Build Definition Test Pull Request
1311577 dotnet/runtime System.IO.Tests.SymbolicLink_Changed_Tests.FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories
1310526 dotnet/runtime [System.IO.Tests.SymbolicLink_Changed_Tests.FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories](https://dev.azure.com/dnceng-public/publ...

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@dotnet-policy-service
Copy link
Contributor

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

…udeSubdirectories test

Add expectedPath filter to ExpectNoEvent call so spurious Create events
from setup (e.g. subDir created just before the FSEvents stream started)
do not cause false test failures on macOS.

Change [ActiveIssue] to be OSX-specific since the root cause is macOS
FSEvents delivering late events near the kFSEventStreamEventIdSinceNow
boundary, and the test now runs cleanly on Linux/Windows.

Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix FileSystemWatcher symbolic link missed event issue Fix flaky FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories test Mar 17, 2026
Copilot AI requested a review from danmoseley March 17, 2026 22:02
@danmoseley
Copy link
Member

@copilot remove the ActiveIssue, since the point of this change is to fix and enable the test.

@danmoseley danmoseley requested a review from Copilot March 18, 2026 00:47
@danmoseley danmoseley marked this pull request as ready for review March 18, 2026 00:47
@danmoseley
Copy link
Member

also @copilot it might be helpful to add some comments around here with examples of each of these path variables ot help readers.

                    action: () => Directory.CreateDirectory(subDirLv2Path),
                    cleanup: () => Directory.Delete(subDirLv2Path),
                    expectedPath: Path.Combine(linkPath, subDir, subDirLv2));

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves reliability and coverage of the FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories test by reducing false failures from unrelated Created events and ensuring the test is only skipped on the affected platform.

Changes:

  • Scope ExpectNoEvent to only fail when a Created event occurs for the specific nested directory path under test.
  • Restrict the existing [ActiveIssue] skip to TestPlatforms.OSX so the test runs on Windows/Linux.

…ate_IncludeSubdirectories test

The expectedPath fix makes the test robust enough to run on all platforms.

Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 18, 2026

@copilot remove the ActiveIssue, since the point of this change is to fix and enable the test.

Done — removed the [ActiveIssue] attribute entirely in c62ed9b. The test now runs on all platforms.

Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 18, 2026

also @copilot it might be helpful to add some comments around here with examples of each of these path variables ot help readers.

...

Added a disk-layout diagram and inline comments on each path variable in 483c78c. The comments now show the relationship between tempDir, tempSubDir, linkPath, and subDirLv2Path, and the expectedPath arguments are annotated with the concrete path they resolve to.

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

Projects

None yet

3 participants