@@ -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