@@ -95,14 +95,54 @@ void Check(bool condition, string message)
9595 Tick ( ) ;
9696 Check ( repo . Calls . Count == 0 , "Manual mode must suppress queued changes and overflow recovery, even with zero throttling." ) ;
9797
98+ preferences . RefreshThrottling = 5000 ;
99+ using ( watcher . Lock ( ) )
100+ {
101+ using ( watcher . Lock ( ) )
102+ {
103+ WorkingCopy ( ) ;
104+ Git ( "HEAD" ) ;
105+ Tick ( ) ;
106+ }
107+
108+ Check ( repo . Calls . Count == 0 , "Nested application operations must not refresh before the outer operation finishes." ) ;
109+ }
110+ Check ( repo . Calls . Count == 7 , "Application operations must refresh in manual mode without waiting for throttling." ) ;
111+ Check ( filesystemWatchers . All ( x => ! x . EnableRaisingEvents ) , "Application refreshes must leave external filesystem hooks disabled." ) ;
112+ repo . Calls . Clear ( ) ;
113+ Tick ( ) ;
114+ Check ( repo . Calls . Count == 0 , "Completing an application operation must not enable filesystem refreshes." ) ;
115+
116+ try
117+ {
118+ using var operation = watcher . Lock ( ) ;
119+ throw new OperationCanceledException ( ) ;
120+ }
121+ catch ( OperationCanceledException )
122+ {
123+ Check ( repo . Calls . Count == 7 , "Cancelled or failed operations must refresh any partial repository changes." ) ;
124+ }
125+ repo . Calls . Clear ( ) ;
126+
127+ var completedOperation = watcher . Lock ( ) ;
128+ completedOperation . Dispose ( ) ;
129+ completedOperation . Dispose ( ) ;
130+ Check ( repo . Calls . Count == 7 , "Disposing an operation twice must refresh only once and preserve the lock count." ) ;
131+ repo . Calls . Clear ( ) ;
132+
98133 using ( var manualWatcher = new Watcher ( repo , root , Path . Combine ( root , ".git" ) ) )
99134 {
100135 var manualFilesystemWatchers = ( List < FileSystemWatcher > ) typeof ( Watcher ) . GetField ( "_watchers" , flags ) . GetValue ( manualWatcher ) ;
101136 // Run the startup action explicitly as well, to check that it cannot enable hooks in manual mode.
102137 typeof ( Watcher ) . GetMethod ( "UpdateWatching" , flags ) . Invoke ( manualWatcher , null ) ;
103138 Check ( manualFilesystemWatchers . All ( x => ! x . EnableRaisingEvents ) , "Repositories opened in manual mode must leave hooks disabled." ) ;
139+ var operation = manualWatcher . Lock ( ) ;
140+ manualWatcher . Dispose ( ) ;
141+ operation . Dispose ( ) ;
142+ Check ( repo . Calls . Count == 0 , "An operation finishing after the repository closes must not refresh it." ) ;
104143 }
105144
145+ preferences . RefreshThrottling = 0 ;
106146 preferences . ManualRefresh = false ;
107147 Check ( filesystemWatchers . All ( x => x . EnableRaisingEvents ) , "Returning to automatic mode must re-enable filesystem hooks." ) ;
108148 Thread . Sleep ( 1 ) ;
@@ -111,6 +151,10 @@ void Check(bool condition, string message)
111151 repo . Calls . Clear ( ) ;
112152 Tick ( ) ;
113153 Check ( repo . Calls . Count == 0 , "Automatic recovery must refresh only once." ) ;
154+ using ( watcher . Lock ( ) )
155+ {
156+ }
157+ Check ( repo . Calls . Count == 0 , "Automatic mode must retain its existing event-driven refresh behavior." ) ;
114158 Console . WriteLine ( "Watcher checks passed." ) ;
115159}
116160finally
0 commit comments