11using System ;
22using System . IO ;
3+ using System . Linq ;
4+ using System . Text ;
35using System . Threading ;
46using System . Threading . Tasks ;
57using Xunit ;
68
79namespace StackExchange . Redis . Tests
810{
11+ [ RunPerProtocol ]
912 public class SyncContextTests ( ITestOutputHelper testOutput ) : TestBase ( testOutput )
1013 {
1114 /* Note A (referenced below)
@@ -72,6 +75,7 @@ public async Task SyncConfigure()
7275 using var ctx = new MySyncContext ( Writer ) ;
7376 await using var conn = Create ( ) ;
7477 Assert . Equal ( 0 , ctx . OpCount ) ;
78+ // ReSharper disable once MethodHasAsyncOverload - very deliberate
7579 Assert . True ( conn . Configure ( ) ) ;
7680 Assert . Equal ( 0 , ctx . OpCount ) ;
7781 }
@@ -130,7 +134,7 @@ public MySyncContext(TextWriter log)
130134
131135 public override void Post ( SendOrPostCallback d , object ? state )
132136 {
133- Log ( _log , "sync-ctx: Post" ) ;
137+ Log ( _log , $ "sync-ctx: Post { Format ( d , state ) } ") ;
134138 Incr ( ) ;
135139 ThreadPool . QueueUserWorkItem (
136140 static state =>
@@ -143,14 +147,32 @@ public override void Post(SendOrPostCallback d, object? state)
143147
144148 private void Invoke ( SendOrPostCallback d , object ? state )
145149 {
146- Log ( _log , "sync-ctx: Invoke" ) ;
150+ Log ( _log , $ "sync-ctx: Invoke { Format ( d , state ) } ") ;
147151 if ( ! IsCurrent ) SetSynchronizationContext ( this ) ;
148152 d ( state ) ;
149153 }
150154
155+ private static string Format ( SendOrPostCallback ? d , object ? state )
156+ {
157+ if ( d is null ) return "" ;
158+ string name = d . IsSingle ( ) ? d . Method . Name : GetNames ( d ) ;
159+ return state is null ? name : $ "{ name } :{ state } ";
160+
161+ static string GetNames ( SendOrPostCallback d )
162+ {
163+ var sb = new StringBuilder ( ) ;
164+ foreach ( var x in d . AsEnumerable ( ) )
165+ {
166+ if ( sb . Length != 0 ) sb . Append ( "," ) ;
167+ sb . Append ( x . Method . Name ) ;
168+ }
169+ return sb . ToString ( ) ;
170+ }
171+ }
172+
151173 public override void Send ( SendOrPostCallback d , object ? state )
152174 {
153- Log ( _log , "sync-ctx: Send" ) ;
175+ Log ( _log , $ "sync-ctx: Send { Format ( d , state ) } ") ;
154176 Incr ( ) ;
155177 Invoke ( d , state ) ;
156178 }
0 commit comments