Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] Add tests for AppDomainUnloadedException handling
As described on https://msdn.microsoft.com/en-us/library/system.appdomainunloadedexception(v=vs.110).aspx#Anchor_6
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
class Driver | ||
{ | ||
static void ThrowTP () | ||
{ | ||
ManualResetEvent mre = new ManualResetEvent (false); | ||
|
||
ThreadPool.QueueUserWorkItem (_ => { try { throw new AppDomainUnloadedException (); } finally { mre.Set (); } }); | ||
|
||
if (!mre.WaitOne (5000)) | ||
Environment.Exit (1); | ||
|
||
/* Wait for exception unwinding */ | ||
Thread.Sleep (500); | ||
} | ||
|
||
static void ThrowThread () | ||
{ | ||
Thread thread = new Thread (_ => { throw new AppDomainUnloadedException (); }); | ||
thread.Start (); | ||
thread.Join (); | ||
} | ||
|
||
static int Main (string[] args) | ||
{ | ||
ThrowTP (); | ||
ThrowThread (); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
class Driver | ||
{ | ||
/* expected exit code: 255 */ | ||
static void Main (string[] args) | ||
{ | ||
if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null) | ||
AppDomain.CurrentDomain.UnhandledException += (s, e) => {}; | ||
|
||
throw new AppDomainUnloadedException (); | ||
} | ||
} |