Repository navigation
Conversation
…mWatcher The mock now copies the runtime watcher and only replaces the platform part, so changes outside the watched path no longer fill the buffer and the watcher reacts like the real one per platform. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ent and prefix siblings Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fter Dispose Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e overflow gap Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tick the box to add this pull request to the merge queue (same as
|
[Medium impact] The changes affect event delivery and reporting across the mock file watcher feature. Fix concurrent event subscription updates and satisfy the explicit repository requirements before merging. Findings
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🚀 Benchmark ResultsCompared to Memory
Time
CompleteTestBenchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V45 4.44GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10 InitializationBenchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 7763 2.76GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v3 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10 MockCreationBenchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10 FileRoundTripBenchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain InvocationCount=4096 IterationCount=15 LaunchCount=1 UnrollFactor=1 WarmupCount=10 FileInfoBenchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V45 4.22GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain InvocationCount=65536 IterationCount=15 LaunchCount=1 UnrollFactor=1 WarmupCount=10 FileStreamBenchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain InvocationCount=2048 IterationCount=15 LaunchCount=1 UnrollFactor=1 WarmupCount=10 DirectoryTreeBenchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 7763 2.92GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v3 Job=InProcess Toolchain=InProcessEmitToolchain InvocationCount=512 IterationCount=15 LaunchCount=1 UnrollFactor=1 WarmupCount=10 Enumeration10Benchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) Intel Xeon Platinum 8370C CPU 2.80GHz (Max: 3.46GHz), 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain InvocationCount=16384 IterationCount=15 LaunchCount=1 UnrollFactor=1 WarmupCount=10 Enumeration1000Benchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain InvocationCount=512 IterationCount=15 LaunchCount=1 UnrollFactor=1 WarmupCount=10 |
…ET Framework Matches the real .NET Framework watcher, which does not flow the ExecutionContext of the caller (test ported from the dotnet runtime). The mock tests now capture the test cancellation token outside of the handlers.
Ported from the dotnet runtime FileSystemWatcher tests (src/libraries/System.IO.FileSystem.Watcher/tests).
Ported from the dotnet runtime FileSystemWatcher tests (src/libraries/System.IO.FileSystem.Watcher/tests).
Ported from the dotnet runtime FileSystemWatcher tests (src/libraries/System.IO.FileSystem.Watcher/tests).
…irectories Ported from the dotnet runtime FileSystemWatcher tests (src/libraries/System.IO.FileSystem.Watcher/tests).
Ported from the dotnet runtime FileSystemWatcher tests (src/libraries/System.IO.FileSystem.Watcher/tests).
…threading Ported from the dotnet runtime FileSystemWatcher tests (src/libraries/System.IO.FileSystem.Watcher/tests).
Ported from the dotnet runtime FileSystemWatcher tests (src/libraries/System.IO.FileSystem.Watcher/tests).
…her kind Ported from the dotnet runtime FileSystemWatcher tests (src/libraries/System.IO.FileSystem.Watcher/tests).
Ported from the dotnet runtime FileSystemWatcher tests (src/libraries/System.IO.FileSystem.Watcher/tests).
…ing object Mirrors the dotnet runtime InternalBufferSize_SynchronizingObject test, which only runs on Windows, for the mock on every simulated platform.
Ported from the dotnet runtime FileSystemWatcher tests (src/libraries/System.IO.FileSystem.Watcher/tests). The behavior was measured on Linux, macOS and Windows for .NET 8 to 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Added the dotnet tests for the watcher too and the fixes |
…inux and mac variants
… the restart test
| ); | ||
| } | ||
|
|
||
| private static Task RunDelivery(Func<Task> delivery, CancellationToken token) |
There was a problem hiding this comment.
issue: On .NET Framework the delivery thread registers property reads in the statistics
Since the delivery no longer flows the ExecutionContext on .NET Framework, it also loses the AsyncLocal gate of the statistics that the EnableRaisingEvents setter holds while it starts the task. Every public property that the delivery thread reads is now recorded: after one delivered Created event, Statistics.FileSystemWatcher[path] contains SynchronizingObject{get;}, and a rename adds IncludeSubdirectories{get;}. On main and on .NET the statistics stay clean.
Suggestion: read the backing state instead of the public properties inside the mock: SynchronizingObject in InvokeOn, OnError and OnRenamed (Mock.cs:619, :761, :789), IncludeSubdirectories in IsInWatchedPath and the rename methods (Testably.cs:692, :846 and following), NotifyFilter in the predicate (Testably.cs:144) and InternalBufferSize in StartRaisingEvents (Testably.cs:87). That also saves the registration overhead on every change.
Repro test for Tests/Testably.Abstractions.Testing.Tests/Statistics/FileSystem/FileSystemWatcherStatisticsTests.cs (fails on net48 with "contained more than one property access: [EnableRaisingEvents{set;}, SynchronizingObject{get;}]", passes on net10.0):
[Test]
public async Task DeliveredEvent_ShouldNotRegisterPropertyAccess()
{
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo");
using IFileSystemWatcher fileSystemWatcher = sut.FileSystemWatcher.New("foo");
using ManualResetEventSlim ms = new();
fileSystemWatcher.Created += (_, _) => ms.Set();
fileSystemWatcher.EnableRaisingEvents = true;
sut.Directory.CreateDirectory(sut.Path.Combine("foo", "bar"));
await That(ms.Wait(10000)).IsTrue();
await That(sut.Statistics.FileSystemWatcher["foo"])
.OnlyContainsPropertySetAccess(nameof(IFileSystemWatcher.EnableRaisingEvents));
}|
|
||
| No platform reports a change of the watched directory itself, neither when its timestamps or attributes change nor when it is recreated after a deletion, also with `IncludeSubdirectories` and every `NotifyFilters` value. The mock ignores these changes as well. | ||
|
|
||
| ## Known gaps |
There was a problem hiding this comment.
suggestion: Renames in a subdirectory of a watched symbolic link are not reported yet. I would either fix it or report it as a known gap.
…ion notice to the adapted files
…bolic link is removed
…tatistics stay clean on .net framework
…r is full A move of the watched directory no longer takes a place in the buffer, and each queued change carries the location it was recorded under. Buffers, overflows and the removal of the watched directory now follow the measured behavior of Windows, Linux and macOS per .NET version.
While trying to fix #1227 a lot of follow up issues arose and their fixes had a lot of regressions (see #1232).
I also prepared a smaller fix, which only includes the buffer overflow, without the other fixes see #1274
To fix everything in one go, I copied the dotnet FileSystemWatcher and modified it to fit our mocked file system.
FileSystemWatcherMock.cs contains mostly the dotnet copied code
FileSystemWatcherMock.Testably.cs contains the platform specific implementation.
I intentionally kept these separate so changes on the dotnet one can be easier mirrored.
Removing of "Deep" in the events table, originally I added it because Windows had Changed events on it, but we didn't implement them, since we couldn't reliably get them to work on different windows versions, so Deep was equal to Nested.