Skip to content

Commit fe2f1ff

Browse files
authored
Merge pull request #17 from tgiachi/fix/flaky-filewatcher-debounce
test(core): stabilise flaky FileWatcher debounce test
2 parents 782f4db + 524a3ba commit fe2f1ff

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

tests/SquidStd.Tests/Core/Files/FileWatcherServiceTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,25 @@ public async Task Watch_NestedSubdirectory_PublishesEvent()
8888
[Fact]
8989
public async Task Watch_RapidWritesToSameFile_DebouncesToSingleEvent()
9090
{
91+
// A generous debounce window so the rapid writes reliably collapse into one event even when a
92+
// loaded CI runner pauses (scheduler/GC) between writes: a 200ms window was prone to splitting
93+
// the burst across two windows and emitting two events.
94+
var rapidDebounce = TimeSpan.FromSeconds(1);
9195
var directory = NewTempDirectory();
9296
var file = Path.Combine(directory, "busy.txt");
9397
using var bus = new EventBusService();
9498
var collector = Subscribe(bus);
95-
using var watcher = new FileWatcherService(bus, Debounce);
99+
using var watcher = new FileWatcherService(bus, rapidDebounce);
96100
watcher.Watch(directory);
97101

102+
// Synchronous, tight loop: no await points the scheduler can preempt mid-burst.
98103
for (var i = 0; i < 5; i++)
99104
{
100-
await File.WriteAllTextAsync(file, $"v{i}");
105+
File.WriteAllText(file, $"v{i}");
101106
}
102107

103108
Assert.True(await collector.WaitForAsync(1, Timeout));
104-
await Task.Delay(Debounce * 4);
109+
await Task.Delay(rapidDebounce * 2);
105110

106111
Assert.Single(collector.Events, e => Path.GetFileName(e.FullPath) == "busy.txt");
107112
}

0 commit comments

Comments
 (0)