This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
src/System.Net.Sockets/tests/FunctionalTests Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 44
55using System . IO ;
66using System . Runtime . CompilerServices ;
7+ using System . Text ;
78using System . Threading ;
89using System . Threading . Tasks ;
910using Xunit ;
@@ -26,8 +27,13 @@ public Task ExecutionContext_FlowsOnlyOnceAcrossAsyncOperations()
2627 client . Connect ( listener . LocalEndPoint ) ;
2728 using ( Socket server = listener . Accept ( ) )
2829 {
30+ var stackLog = new StringBuilder ( ) ;
2931 int executionContextChanges = 0 ;
30- var asyncLocal = new AsyncLocal < int > ( _ => executionContextChanges ++ ) ;
32+ var asyncLocal = new AsyncLocal < int > ( _ =>
33+ {
34+ executionContextChanges ++ ;
35+ stackLog . AppendLine ( $ "#{ executionContextChanges } : { Environment . StackTrace } ") ;
36+ } ) ;
3137 Assert . Equal ( 0 , executionContextChanges ) ;
3238
3339 int numAwaits = 20 ;
@@ -44,7 +50,14 @@ public Task ExecutionContext_FlowsOnlyOnceAcrossAsyncOperations()
4450
4551 // This doesn't count EC changes where EC.Run is passed the same context
4652 // as is current, but it's the best we can track via public API.
47- Assert . InRange ( executionContextChanges , 1 , numAwaits * 3 ) ; // at most: 1 / AsyncLocal change + 1 / suspend + 1 / resume
53+ try
54+ {
55+ Assert . InRange ( executionContextChanges , 1 , numAwaits * 3 ) ; // at most: 1 / AsyncLocal change + 1 / suspend + 1 / resume
56+ }
57+ catch ( Exception e )
58+ {
59+ throw new Exception ( $ "{ nameof ( executionContextChanges ) } == { executionContextChanges } with log: { stackLog . ToString ( ) } ", e ) ;
60+ }
4861 }
4962 }
5063 } ) ;
You can’t perform that action at this time.
0 commit comments