blob: 9f9720bc2bc17e5715fc3be970ce3af4fb4e141e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
using System;
using System.Threading.Tasks;
using System.Threading;
using System.Reflection;
using System.Linq;
class Tester
{
async Task<int> TestException_1 ()
{
await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
return 1;
}
async Task TestException_2 ()
{
await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
}
async Task TestException_3 ()
{
Func<Task> a = async () => await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
await a ().ConfigureAwait (false);
}
async Task<int> TestException_4 ()
{
try {
await Task.Factory.StartNew (() => 5).ConfigureAwait (false);
} finally {
throw new ApplicationException ();
}
}
async Task<int> TestException_5 ()
{
int state = 0;
try {
await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
state = 1;
} catch (ArgumentException) {
state = 2;
} finally {
if (state == 2)
throw new ApplicationException ();
}
return 1;
}
async Task<int> TestException_6 ()
{
try {
await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
} catch (ArgumentException) {
throw new ApplicationException ();
}
return 1;
}
async Task<int> TestException_7 ()
{
try {
await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
} catch (ArgumentException e) {
if (e.StackTrace.Contains (".MoveNext"))
throw new ApplicationException ();
}
return 1;
}
static bool RunTest (MethodInfo test)
{
Console.Write ("Running test {0, -25}", test.Name);
try {
Task t = test.Invoke (new Tester (), null) as Task;
try {
if (!Task.WaitAll (new[] { t }, 1000)) {
Console.WriteLine ("FAILED (Timeout)");
return false;
}
} catch (AggregateException) {
}
if (t.Status != TaskStatus.Faulted) {
Console.WriteLine ("FAILED (Status={0})", t.Status);
return false;
}
if (!(t.Exception.InnerException is ApplicationException)) {
Console.WriteLine ("FAILED with wrong exception");
return false;
}
Console.WriteLine ("OK");
return true;
} catch (Exception e) {
Console.WriteLine ("FAILED");
Console.WriteLine (e.ToString ());
return false;
}
}
public static int Main ()
{
var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
where test.GetParameters ().Length == 0
orderby test.Name
select RunTest (test);
int failures = tests.Count (a => !a);
Console.WriteLine (failures + " tests failed");
return failures;
}
}
|