Merge pull request #5382 from kumpera/pedump_fix
[mono.git] / mono / tests / appdomain-unload.cs
index 8c221f8c3b996aa7ec0e7224141a29bae3561d4e..e5ce63689219231bba99f26ef95eb35baafc8c1f 100644 (file)
@@ -1,5 +1,7 @@
 using System;
 using System.Threading;
+using System.Reflection;
+using System.Runtime.Remoting;
 
 [Serializable]
 public class Foo {
@@ -9,6 +11,20 @@ public class Foo {
        }
 }
 
+public class Bar : MarshalByRefObject {
+       public int test (int x) {
+               Console.WriteLine ("in " + Thread.GetDomain ().FriendlyName);
+               return x + 1;
+       }
+
+       public void start_wait () {
+               Action a = delegate () {
+                       Thread.Sleep (10000);
+               };
+               a.BeginInvoke (null, null);
+       }
+}
+
 [Serializable]
 public class SlowFinalize {
 
@@ -82,15 +98,26 @@ public class UnloadThread {
        }
 }
 
+class CrossDomainTester : MarshalByRefObject
+{
+}
+
 public class Tests
 {
-       public static int Main() {
-               return TestDriver.RunTests (typeof (Tests));
+       public static int Main(string[] args) {
+               if (args.Length == 0)
+                       return TestDriver.RunTests (typeof (Tests), new String[] { "-v" });
+               else
+                       return TestDriver.RunTests (typeof (Tests), args);
        }
 
        public static int test_0_unload () {
                for (int i = 0; i < 10; ++i) {
                        AppDomain appDomain = AppDomain.CreateDomain("Test-unload" + i);
+
+                       appDomain.CreateInstanceAndUnwrap (
+                               typeof (CrossDomainTester).Assembly.FullName, "CrossDomainTester");
+
                        AppDomain.Unload(appDomain);
                }
 
@@ -143,6 +170,8 @@ public class Tests
                return 0;
        }
 
+       /* In recent mono versions, there is no unload timeout */
+       /*
        public static int test_0_unload_with_active_threads_timeout () {
                AppDomain domain = AppDomain.CreateDomain ("Test4");
                BThread o = (BThread)domain.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "BThread");
@@ -160,6 +189,25 @@ public class Tests
 
                return 1;
        }
+       */
+
+       static void Worker (object x) {
+               Thread.Sleep (100000);
+       }
+
+       public static void invoke_workers () {
+               for (int i = 0; i < 1; i ++)
+                       ThreadPool.QueueUserWorkItem (Worker);
+       }
+
+       public static int test_0_unload_with_threadpool () {
+               AppDomain domain = AppDomain.CreateDomain ("test_0_unload_with_threadpool");
+
+               domain.DoCallBack (new CrossAppDomainDelegate (invoke_workers));
+               AppDomain.Unload (domain);
+
+               return 0;
+       }
 
        /*
         * This test is not very deterministic since the thread which enqueues
@@ -204,6 +252,36 @@ public class Tests
                return 0;
        }
 
+       public static int test_0_invoke_after_unload () {
+               AppDomain domain = AppDomain.CreateDomain ("DeadInvokeTest");
+               Bar bar = (Bar)domain.CreateInstanceAndUnwrap (typeof (Tests).Assembly.FullName, "Bar");
+               int x;
+
+               if (!RemotingServices.IsTransparentProxy(bar))
+                       return 3;
+
+               AppDomain.Unload (domain);
+
+               try {
+                       x = bar.test (123);
+                       if (x == 124)
+                               return 1;
+                       return 2;
+               } catch (Exception e) {
+                       return 0;
+               }
+       }
+
+       public static int test_0_abort_wait () {
+               AppDomain domain = AppDomain.CreateDomain ("AbortWait");
+               Bar bar = (Bar)domain.CreateInstanceAndUnwrap (typeof (Tests).Assembly.FullName, "Bar");
+               int x;
+
+               bar.start_wait ();
+               AppDomain.Unload (domain);
+               return 0;
+       }
+
        // FIXME: This does not work yet, because the thread is finalized too
        // early
        /*