@@ -6,13 +6,18 @@ namespace DotNext.Runtime.CompilerServices;
66public sealed class SpawningAsyncTaskMethodBuilderTests : Test
77{
88 [ Fact ]
9- public static Task ForkAsyncMethodWithResult ( )
9+ public static async Task ForkAsyncMethodWithResult ( )
1010 {
11- return Sum ( 40 , 2 , Thread . CurrentThread . ManagedThreadId ) ;
11+ using var resetEvent = new ManualResetEventSlim ( initialState : false ) ;
12+ var task = Sum ( 40 , 2 , Thread . CurrentThread . ManagedThreadId ) ;
13+ True ( resetEvent . Wait ( DefaultTimeout ) ) ;
14+
15+ Equal ( 42 , await task ) ;
1216
1317 [ AsyncMethodBuilder ( typeof ( SpawningAsyncTaskMethodBuilder < > ) ) ]
14- static async Task < int > Sum ( int x , int y , int callerThreadId )
18+ async Task < int > Sum ( int x , int y , int callerThreadId )
1519 {
20+ resetEvent . Set ( ) ;
1621 NotEqual ( callerThreadId , Thread . CurrentThread . ManagedThreadId ) ;
1722
1823 await Task . CompletedTask ;
@@ -21,13 +26,18 @@ static async Task<int> Sum(int x, int y, int callerThreadId)
2126 }
2227
2328 [ Fact ]
24- public static Task ForkAsyncMethodWithoutResult ( )
29+ public static async Task ForkAsyncMethodWithoutResult ( )
2530 {
26- return CheckThreadId ( Thread . CurrentThread . ManagedThreadId ) ;
31+ using var resetEvent = new ManualResetEventSlim ( initialState : false ) ;
32+ var task = CheckThreadId ( Thread . CurrentThread . ManagedThreadId ) ;
33+ True ( resetEvent . Wait ( DefaultTimeout ) ) ;
34+
35+ await task ;
2736
2837 [ AsyncMethodBuilder ( typeof ( SpawningAsyncTaskMethodBuilder ) ) ]
29- static async Task CheckThreadId ( int callerThreadId )
38+ async Task CheckThreadId ( int callerThreadId )
3039 {
40+ resetEvent . Set ( ) ;
3141 NotEqual ( callerThreadId , Thread . CurrentThread . ManagedThreadId ) ;
3242
3343 await Task . CompletedTask ;
@@ -37,14 +47,17 @@ static async Task CheckThreadId(int callerThreadId)
3747 [ Fact ]
3848 public static async Task CancellationOfSpawnedMethod ( )
3949 {
50+ using var resetEvent = new ManualResetEventSlim ( initialState : false ) ;
4051 var task = CheckThreadId ( Thread . CurrentThread . ManagedThreadId , new ( true ) ) ;
52+ True ( resetEvent . Wait ( DefaultTimeout ) ) ;
4153
4254 await task . ConfigureAwait ( ConfigureAwaitOptions . ContinueOnCapturedContext | ConfigureAwaitOptions . SuppressThrowing ) ;
4355 True ( task . IsCanceled ) ;
4456
4557 [ AsyncMethodBuilder ( typeof ( SpawningAsyncTaskMethodBuilder ) ) ]
46- static async Task CheckThreadId ( int callerThreadId , CancellationToken token )
58+ async Task CheckThreadId ( int callerThreadId , CancellationToken token )
4759 {
60+ resetEvent . Set ( ) ;
4861 NotEqual ( callerThreadId , Thread . CurrentThread . ManagedThreadId ) ;
4962
5063 await Task . Delay ( DefaultTimeout , token ) ;
0 commit comments