File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -45,4 +45,18 @@ private protected static ReadOnlySequence<T> ToReadOnlySequence<T>(ReadOnlyMemor
4545 private protected static Action < T > Same < T > ( T expected )
4646 where T : class
4747 => actual => Same ( expected , actual ) ;
48+
49+ protected static TResult SuspendContext < TResult > ( Func < TResult > func )
50+ {
51+ var currentContext = SynchronizationContext . Current ;
52+ SynchronizationContext . SetSynchronizationContext ( null ) ;
53+ try
54+ {
55+ return func ( ) ;
56+ }
57+ finally
58+ {
59+ SynchronizationContext . SetSynchronizationContext ( currentContext ) ;
60+ }
61+ }
4862}
Original file line number Diff line number Diff line change @@ -132,7 +132,7 @@ public static async Task WorkerProtectedWithLease()
132132 await using var consumer = new TestLeaseConsumer ( provider ) ;
133133 True ( await consumer . TryAcquireAsync ( ) ) ;
134134
135- var result = await consumer . ExecuteAsync ( Worker ) ;
135+ var result = await SuspendContext ( ( ) => consumer . ExecuteAsync ( Worker ) ) ;
136136 Equal ( 42 , result ) ;
137137
138138 static async Task < int > Worker ( CancellationToken token )
You can’t perform that action at this time.
0 commit comments