EncoderReplacementFallbackBuffer.Reset() did not really reset its internals.
[mono-project/dkf.git] / mcs / tests / test-async-07.cs
blob55d7b08c89b51de6e0e87f0c97078858b31daee5
1 // Compiler options: -langversion:future
3 using System;
4 using System.Threading;
5 using System.Threading.Tasks;
7 class Program
9 static int Main ()
11 var mre_l = new ManualResetEvent (false);
12 var mre = new ManualResetEvent (false);
14 Func<string, Task<string>> f = async l =>
15 await Task.Factory.StartNew (() => {
16 if (!mre_l.WaitOne (3000))
17 throw new ApplicationException ("3");
19 return l;
20 });
22 var r = f ("a");
23 mre_l.Set ();
24 if (!r.Wait (3000))
25 return 1;
27 if (r.Result != "a")
28 return 11;
30 mre_l.Reset ();
32 Func<Task> ff = async () =>
33 await Task.Factory.StartNew (() => {
34 if (!mre_l.WaitOne (3000))
35 throw new ApplicationException ("3");
36 });
38 var rr = ff ();
39 mre_l.Set ();
40 if (!rr.Wait (3000))
41 return 2;
43 Func<short, Task<short>> f2 = async l => l;
45 var r2 = f2 (88);
46 if (r2.Result != 88)
47 return 3;
49 mre.Reset ();
50 mre_l.Reset ();
51 Action a = async () => await Task.Factory.StartNew (() => {
52 if (!mre_l.WaitOne (3000))
53 throw new ApplicationException ("4");
54 mre.Set ();
55 }, CancellationToken.None);
57 a ();
58 mre_l.Set ();
59 if (!mre.WaitOne (3000))
60 return 4;
62 Console.WriteLine ("ok");
63 return 0;