File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed
Sentry.Tests/Internals/Http Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 22using System . Collections ;
33using System . Collections . Generic ;
44using System . Linq ;
5+ using System . Threading ;
56using System . Threading . Tasks ;
67using NLog ;
78using NLog . Common ;
@@ -471,17 +472,19 @@ public async Task LogManager_WhenFlushCalled_CallsSentryFlushAsync()
471472
472473 var testDisposable = Substitute . For < IDisposable > ( ) ;
473474
475+ var evt = new ManualResetEventSlim ( ) ;
474476 AsyncContinuation continuation = e =>
475477 {
476478 testDisposable . Dispose ( ) ;
479+ evt . Set ( ) ;
477480 } ;
478481
479482 factory . Flush ( continuation , timeout ) ;
480483
481- await Task . Delay ( timeout ) ;
484+ Assert . True ( evt . Wait ( timeout ) ) ;
482485
483486 testDisposable . Received ( ) . Dispose ( ) ;
484- hub . Received ( ) . FlushAsync ( Arg . Any < TimeSpan > ( ) ) . GetAwaiter ( ) . GetResult ( ) ;
487+ await hub . Received ( ) . FlushAsync ( Arg . Any < TimeSpan > ( ) ) ;
485488 }
486489
487490 [ Fact ]
Original file line number Diff line number Diff line change @@ -68,34 +68,36 @@ public async Task EnvelopeReachesInnerTransport()
6868 sentEnvelope . Should ( ) . BeEquivalentTo ( envelope , o => o . Excluding ( x => x . Items [ 0 ] . Header ) ) ;
6969 }
7070
71- [ Fact ( Timeout = 7000 ) ]
71+ [ Fact ( Timeout = 5000 ) ]
7272 public async Task MaintainsLimit ( )
7373 {
7474 // Arrange
7575 using var cacheDirectory = new TempDirectory ( ) ;
7676 var options = new SentryOptions
7777 {
7878 CacheDirectoryPath = cacheDirectory . Path ,
79- MaxQueueItems = 3
79+ MaxQueueItems = 2
8080 } ;
8181
8282 var innerTransport = Substitute . For < ITransport > ( ) ;
8383
84- // Introduce enough delay for the cache to overflow under normal circumstances
84+ var evt = new ManualResetEventSlim ( ) ;
85+ // Block until we're done
8586 innerTransport
86- . SendEnvelopeAsync ( Arg . Any < Envelope > ( ) , Arg . Any < CancellationToken > ( ) )
87- . Returns ( Task . Delay ( 3000 ) ) ;
87+ . When ( t => t . SendEnvelopeAsync ( Arg . Any < Envelope > ( ) , Arg . Any < CancellationToken > ( ) ) )
88+ . Do ( _ => evt . Wait ( ) ) ;
8889
8990 await using var transport = new CachingTransport ( innerTransport , options ) ;
9091
9192 // Act & assert
92- for ( var i = 0 ; i < 20 ; i ++ )
93+ for ( var i = 0 ; i < options . MaxQueueItems + 2 ; i ++ )
9394 {
9495 using var envelope = Envelope . FromEvent ( new SentryEvent ( ) ) ;
9596 await transport . SendEnvelopeAsync ( envelope ) ;
9697
9798 transport . GetCacheLength ( ) . Should ( ) . BeLessOrEqualTo ( options . MaxQueueItems ) ;
9899 }
100+ evt . Set ( ) ;
99101 }
100102
101103 [ Fact ( Timeout = 7000 ) ]
You can’t perform that action at this time.
0 commit comments