-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix flaky FileWatcherTests.DeleteSubfolder test #54801
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
Changes from all commits
5ff8316
c6054d1
c2c2015
cb5b765
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,21 +40,23 @@ private async Task TestOperation( | |
| } | ||
|
|
||
| var operationCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); | ||
| var expectedSet = new HashSet<ChangedPath>(expectedChanges); | ||
| Assert.True(expectedSet.Count == expectedChanges.Length, "expectedChanges must not contain duplicates."); | ||
| var filesChanged = new HashSet<ChangedPath>(); | ||
|
|
||
| EventHandler<ChangedPath> handler = null; | ||
| handler = (_, f) => | ||
| { | ||
| if (filesChanged.Add(f)) | ||
| { | ||
| output.WriteLine($"Observed new {f.Kind}: '{f.Path}' ({filesChanged.Count} out of {expectedChanges.Length})"); | ||
| output.WriteLine($"Observed new {f.Kind}: '{f.Path}' ({filesChanged.Count} changes, {expectedSet.Count(e => filesChanged.Contains(e))} out of {expectedChanges.Length} expected)"); | ||
| } | ||
| else | ||
| { | ||
| output.WriteLine($"Already seen {f.Kind}: '{f.Path}'"); | ||
| } | ||
|
|
||
| if (filesChanged.Count == expectedChanges.Length) | ||
| if (expectedSet.IsSubsetOf(filesChanged)) | ||
| { | ||
| watcher.EnableRaisingEvents = false; | ||
| watcher.OnFileChange -= handler; | ||
|
|
@@ -78,7 +80,10 @@ private async Task TestOperation( | |
| var task = operationCompletionSource.Task; | ||
| await (Debugger.IsAttached ? task : task.TimeoutAfter(DefaultTimeout)); | ||
|
|
||
| AssertEx.SequenceEqual(expectedChanges, filesChanged.OrderBy(x => x.Path)); | ||
| // Verify all expected changes were observed (extra events from the OS are acceptable) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, extra events can cause different watch behavior, so they are generally not acceptable. Are the events non-deterministic on Linux?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can modify the logic so that a test can list specific optional events that may occur. |
||
| var missing = expectedSet.Except(filesChanged).OrderBy(x => x.Path).ToArray(); | ||
| Assert.True(missing.Length == 0, | ||
| $"Expected changes not observed: {string.Join(", ", missing.Select(m => $"{m.Kind}: '{m.Path}'"))}\nActual changes: {string.Join(", ", filesChanged.OrderBy(x => x.Path).Select(m => $"{m.Kind}: '{m.Path}'"))}"); | ||
|
MichaelSimons marked this conversation as resolved.
|
||
| } | ||
|
|
||
| private sealed class TestFileWatcher(ILogger logger) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.