File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
BitFaster.Caching.UnitTests/Atomic Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,48 @@ public async Task WhenCallersRunConcurrentlyResultIsFromWinner()
114114 winnerCount . Should ( ) . Be ( 1 ) ;
115115 }
116116
117+ [ Fact ]
118+ public async Task WhenCallersRunConcurrentlyWithFailureSameExceptionIsPropagated ( )
119+ {
120+ var enter = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
121+ var resume = new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
122+
123+ var atomicFactory = new AsyncAtomicFactory < int , int > ( ) ;
124+
125+ var first = atomicFactory . GetValueAsync ( 1 , async k =>
126+ {
127+ enter . SetResult ( true ) ;
128+ await resume . Task ;
129+
130+ throw new ArithmeticException ( "1" ) ;
131+ } ) . AsTask ( ) ;
132+
133+ var second = atomicFactory . GetValueAsync ( 1 , async k =>
134+ {
135+ enter . SetResult ( true ) ;
136+ await resume . Task ;
137+
138+ throw new InvalidOperationException ( "2" ) ;
139+ } ) . AsTask ( ) ;
140+
141+ await enter . Task ;
142+ resume . SetResult ( true ) ;
143+
144+ // Both tasks will throw, but the first one to complete will propagate its exception
145+ // Both exceptions should be the same. If they are not, there will be an aggregate exception.
146+ try
147+ {
148+ await Task . WhenAll ( first , second )
149+ . TimeoutAfter ( TimeSpan . FromSeconds ( 5 ) , "Tasks did not complete within the expected time. Exceptions are not propagated between callers correctly." ) ;
150+ }
151+ catch ( ArithmeticException )
152+ {
153+ }
154+ catch ( InvalidOperationException )
155+ {
156+ }
157+ }
158+
117159 [ Fact ]
118160 public void WhenValueNotCreatedHashCodeIsZero ( )
119161 {
You can’t perform that action at this time.
0 commit comments