File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
BitFaster.Caching.UnitTests/Atomic Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,49 @@ public async Task WhenCallersRunConcurrentlyResultIsFromWinner()
156156 winnerCount . Should ( ) . Be ( 1 ) ;
157157 }
158158
159+
160+ [ Fact ]
161+ public async Task WhenCallersRunConcurrentlyWithFailureSameExceptionIsPropagated ( )
162+ {
163+ var enter = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
164+ var resume = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
165+
166+ var atomicFactory = new ScopedAsyncAtomicFactory < int , IntHolder > ( ) ;
167+
168+ var first = atomicFactory . TryCreateLifetimeAsync ( 1 , async k =>
169+ {
170+ enter . SetResult ( true ) ;
171+ await resume . Task ;
172+
173+ throw new ArithmeticException ( "1" ) ;
174+ } ) . AsTask ( ) ; ;
175+
176+ var second = atomicFactory . TryCreateLifetimeAsync ( 1 , async k =>
177+ {
178+ enter . SetResult ( true ) ;
179+ await resume . Task ;
180+
181+ throw new InvalidOperationException ( "2" ) ;
182+ } ) . AsTask ( ) ;
183+
184+ await enter . Task ;
185+ resume . SetResult ( true ) ;
186+
187+ // Both tasks will throw, but the first one to complete will propagate its exception
188+ // Both exceptions should be the same. If they are not, there will be an aggregate exception.
189+ try
190+ {
191+ await Task . WhenAll ( first , second )
192+ . TimeoutAfter ( TimeSpan . FromSeconds ( 5 ) , "Tasks did not complete within the expected time. Exceptions are not propagated between callers correctly." ) ;
193+ }
194+ catch ( ArithmeticException )
195+ {
196+ }
197+ catch ( InvalidOperationException )
198+ {
199+ }
200+ }
201+
159202 [ Fact ]
160203 public async Task WhenDisposedWhileInitResultIsDisposed ( )
161204 {
You can’t perform that action at this time.
0 commit comments