Merge pull request #2670 from lambdageek/dev/monoerror-mono_runtime_object_init
[mono.git] / mono / tests / appdomain-thread-abort.cs
index c4fa9ea028660b31a94a3bc842dbc3e175911b52..77015fb7b49aabd7042ddcab855c3dee3227b3b4 100644 (file)
@@ -1,10 +1,36 @@
 using System;
 using System.Threading;
 using System.Runtime.Remoting;
+using System.Reflection;
 
 public class JustSomeClass {
 }
 
+public class Test2 : ContextBoundObject
+{
+       public void Run () {
+               Thread.CurrentThread.Abort ();
+       }
+}
+
+public class Test1 : MarshalByRefObject
+{
+       public bool Run () {
+               AppDomain d = AppDomain.CreateDomain ("foo2");
+
+               var t2 = (Test2)d.CreateInstanceAndUnwrap (Assembly.GetExecutingAssembly().FullName,
+                                                                                                "Test2");
+               try {
+                       t2.Run ();
+               } catch (ThreadAbortException ex) {
+                       Thread.ResetAbort ();
+                       return true;
+               }
+
+               return false;
+       }
+}
+
 public class Test : MarshalByRefObject {
     ThreadAbortException exc;
     public JustSomeClass other;
@@ -168,6 +194,26 @@ public class main {
            return 11;
        }
 
+       // #539394
+       // Calling Thread.Abort () from a remoting call throws a ThreadAbortException which
+       // cannot be caught because the exception handling code is confused by the domain
+       // transitions
+       bool res = false;
+
+       Thread thread = new Thread (delegate () {
+                       AppDomain d = AppDomain.CreateDomain ("foo");
+
+                       var t = (Test1)d.CreateInstanceAndUnwrap (Assembly.GetExecutingAssembly().FullName,
+                                                                                                                 "Test1");
+                       res = t.Run ();
+               });
+
+       thread.Start ();
+       thread.Join ();
+
+       if (!res)
+               return 12;
+
        Console.WriteLine ("done");
 
        return 0;