From 6eef0e52df5af5fb09e2cf0c8d2b0831bf50e2c2 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Fri, 15 Sep 2017 12:34:28 +0300 Subject: [PATCH] [tests] Add test for appdomain 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 | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/mono/tests/appdomain-unload.cs b/mono/tests/appdomain-unload.cs index 9d1790e16ff..07cdf833e8c 100644 --- a/mono/tests/appdomain-unload.cs +++ b/mono/tests/appdomain-unload.cs @@ -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); } -- 2.25.1