[mono/tests] Fix out of tree build.
[mono-project.git] / mcs / tests / test-async-02.cs
blob047f814923d42d27d4de5810ad2dc80d9ed43f75
1 using System;
2 using System.Threading.Tasks;
3 using System.Threading;
5 class C
7 ManualResetEvent mre = new ManualResetEvent (false);
9 public async Task TestTask ()
11 await Call ().ConfigureAwait (false);
14 public async Task TestTask2 ()
16 await Call ().ConfigureAwait (false);
17 return;
20 Task Call ()
22 return Task.Factory.StartNew (() => {
23 mre.WaitOne (3000);
24 Console.WriteLine ("a");
25 });
28 public async Task<int> TestTaskGeneric ()
30 return await CallGeneric ().ConfigureAwait (false);
33 Task<int> CallGeneric ()
35 return Task.Factory.StartNew (() => {
36 mre.WaitOne (3000);
37 return 5;
38 });
41 public static int Main ()
43 var c = new C ();
44 var t = c.TestTask ();
45 if (t.Status != TaskStatus.WaitingForActivation)
46 return 1;
48 c.mre.Set ();
49 if (!Task.WaitAll (new[] { t }, 3000))
50 return 2;
52 if (t.Status != TaskStatus.RanToCompletion)
53 return 3;
55 c = new C ();
56 t = c.TestTask2 ();
57 if (t.Status != TaskStatus.WaitingForActivation)
58 return 4;
60 c.mre.Set ();
61 if (!Task.WaitAll (new[] { t }, 3000))
62 return 5;
64 if (t.Status != TaskStatus.RanToCompletion)
65 return 6;
67 c = new C ();
68 var t2 = c.TestTaskGeneric ();
69 if (t2.Status != TaskStatus.WaitingForActivation)
70 return 7;
72 c.mre.Set ();
73 if (!Task.WaitAll (new[] { t2 }, 3000))
74 return 8;
76 if (t2.Result != 5)
77 return 9;
79 if (t2.Status != TaskStatus.RanToCompletion)
80 return 10;
82 return 0;