[tests] Add test for appdomain
authorVlad Brezae <brezaevlad@gmail.com>
Fri, 15 Sep 2017 09:34:28 +0000 (12:34 +0300)
committerVlad Brezae <brezaevlad@gmail.com>
Fri, 22 Sep 2017 08:08:50 +0000 (11:08 +0300)
Tests that we can unload domain where the threads reset the abort exception and that this exception is converted to AppDomainUnloadedException in the caller domain.

mono/tests/appdomain-unload.cs

index 9d1790e16ff43bac799e9a30ad5a6143ee007a99..07cdf833e8cfafba1993b6111038c77c0da84ba8 100644 (file)
@@ -83,6 +83,40 @@ public class BThread : MarshalByRefObject {
        }
 }
 
+public interface IRunnable {
+       void Run ();
+}
+
+public class MBRObject : MarshalByRefObject, IRunnable {
+       /* XDomain wrappers for invocation */
+       public void Run () {
+               while (true) {
+                       try {
+                               while (true)
+                                       Thread.Sleep (100);
+                       }
+                       catch (ThreadAbortException ex) {
+                               Thread.ResetAbort ();
+                       }
+               }
+       }
+}
+
+public class CBObject : ContextBoundObject, IRunnable {
+       /* Slow corlib path for invocation */
+       public void Run () {
+               while (true) {
+                       try {
+                               while (true)
+                                       Thread.Sleep (100);
+                       }
+                       catch (ThreadAbortException ex) {
+                               Thread.ResetAbort ();
+                       }
+               }
+       }
+}
+
 public class UnloadThread {
 
        AppDomain domain;
@@ -191,6 +225,32 @@ public class Tests
        }
        */
 
+       public static void ThreadStart (object obj)
+       {
+               IRunnable runnable = (IRunnable)obj;
+
+               try {
+                       runnable.Run ();
+               } catch (AppDomainUnloadedException) {
+                       Console.WriteLine ("OK");
+               } catch (ThreadAbortException) {
+                       throw new Exception ();
+               }
+       }
+
+       public static int test_0_unload_reset_abort () {
+               AppDomain domain = AppDomain.CreateDomain ("test_0_unload_reset_abort");
+               MBRObject mbro = (MBRObject) domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "MBRObject");
+               CBObject cbo = (CBObject) domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "CBObject");
+
+               new Thread (ThreadStart).Start (mbro);
+               new Thread (ThreadStart).Start (cbo);
+               Thread.Sleep (100);
+
+               AppDomain.Unload (domain);
+               return 0;
+       }
+
        static void Worker (object x) {
                Thread.Sleep (100000);
        }