Fix test
authorMarek Safar <marek.safar@gmail.com>
Tue, 17 Apr 2012 07:38:40 +0000 (08:38 +0100)
committerMarek Safar <marek.safar@gmail.com>
Tue, 17 Apr 2012 17:31:12 +0000 (18:31 +0100)
mcs/tests/test-async-23.cs
mcs/tests/ver-il-net_4_5.xml

index ed5d3ebe448767636cafda848b3c13dd36de51f6..c702827bba35e8ec1a81ec6425e1efb859a8a766 100644 (file)
@@ -1,5 +1,3 @@
-// Compiler options: -langversion:future
-
 using System;
 using System.Threading;
 using System.Threading.Tasks;
@@ -10,6 +8,12 @@ class MyContext : SynchronizationContext
        public int Completed;
        public int PostCounter;
        public int SendCounter;
+       ManualResetEvent mre;
+       
+       public MyContext (ManualResetEvent mre)
+       {
+               this.mre = mre;
+       }
 
        public override void OperationStarted ()
        {
@@ -26,6 +30,7 @@ class MyContext : SynchronizationContext
        public override void Post (SendOrPostCallback d, object state)
        {
                ++PostCounter;
+               mre.Set ();
                base.Post (d, state);
        }
 
@@ -39,19 +44,28 @@ class MyContext : SynchronizationContext
 
 public class TestPostContext
 {
+       static ManualResetEvent await_mre;
+       
        static async Task<int> Test ()
        {
-               return await Task.Factory.StartNew (() => 1);
+               return await Task.Factory.StartNew (() => { await_mre.WaitOne(); return 1; });
        }
 
        public static int Main ()
        {
-               var context = new MyContext ();
+               var mre = new ManualResetEvent (false);
+               await_mre = new ManualResetEvent (false);
+               var context = new MyContext (mre);
                try {
                        SynchronizationContext.SetSynchronizationContext (context);
                        var t = Test ();
-                       if (!t.Wait (1000))
+                       await_mre.Set ();
+                       if (!t.Wait (3000))
                                return 3;
+                               
+                       // Wait is needed because synchronization is executed as continuation (once task finished)
+                       if (!mre.WaitOne (3000))
+                               return 2;
                } finally {
                        SynchronizationContext.SetSynchronizationContext (null);
                }
@@ -59,9 +73,6 @@ public class TestPostContext
                if (context.Started != 0 || context.Completed != 0 || context.SendCounter != 0)
                        return 1;
 
-               if (context.PostCounter != 1)
-                       return 2;
-
                Console.WriteLine ("ok");
                return 0;
        }
index 8fbc825527eeb99069a483164b022054f0af2942..f15c1b8adb97b1f3a5dc5f88dfe159127dab08eb 100644 (file)
         <size>22</size>
       </method>
       <method name="Void Post(System.Threading.SendOrPostCallback, System.Object)" attrs="198">
-        <size>24</size>
+        <size>36</size>
       </method>
       <method name="Void Send(System.Threading.SendOrPostCallback, System.Object)" attrs="198">
         <size>24</size>
       </method>
-      <method name="Void .ctor()" attrs="6278">
-        <size>7</size>
-      </method>
     </type>
     <type name="TestPostContext">
       <method name="System.Threading.Tasks.Task`1[System.Int32] Test()" attrs="145">
         <size>33</size>
       </method>
       <method name="Int32 Main()" attrs="150">
-        <size>136</size>
+        <size>170</size>
       </method>
       <method name="Void .ctor()" attrs="6278">
         <size>7</size>
         <size>13</size>
       </method>
       <method name="Int32 &lt;&gt;m__0()" attrs="145">
-        <size>9</size>
+        <size>21</size>
+      </method>
+    </type>
+    <type name="MyContext">
+      <method name="Void .ctor(ManualResetEvent)" attrs="6278">
+        <size>15</size>
       </method>
     </type>
   </test>