annotate Implab.Test/RunnableComponentTests.cs @ 205:8200ab154c8a v2

Added ResetState to RunnableComponent to reset in case of failure Added StateChanged event to IRunnable Renamed Promise.SUCCESS -> Promise.Success Added Promise.FromException Renamed Bundle -> PromiseAll in PromiseExtensions
author cin
date Tue, 25 Oct 2016 17:40:33 +0300
parents 4d9830a9bbb8
children 7d07503621fe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
1 using System;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
2 using System.Reflection;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
3 using System.Threading;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
4 using Implab.Parallels;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
5 using Implab.Components;
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
6 using Implab.Test.Mock;
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
7
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
8 #if MONO
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
9
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
10 using NUnit.Framework;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
11 using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
12 using TestMethodAttribute = NUnit.Framework.TestAttribute;
188
3071220371f8 Updated VS project
cin
parents: 185
diff changeset
13 using AssertFailedException = NUnit.Framework.AssertionException;
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
14 #else
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
15
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
16 using Microsoft.VisualStudio.TestTools.UnitTesting;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
17
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
18 #endif
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
19
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
20 namespace Implab.Test {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
21 [TestClass]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
22 public class RunnableComponentTests {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
23
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
24 static void ShouldThrow(Action action) {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
25 try {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
26 action();
188
3071220371f8 Updated VS project
cin
parents: 185
diff changeset
27 Assert.Fail();
3071220371f8 Updated VS project
cin
parents: 185
diff changeset
28 } catch (AssertFailedException) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
29 throw;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
30 } catch {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
31 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
32 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
33
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
34
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
35
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
36 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
37 public void NormalFlowTest() {
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
38 var comp = new MockRunnableComponent(false);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
39
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
40 Assert.AreEqual(ExecutionState.Created, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
41
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
42 comp.Initialize();
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
43
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
44 Assert.AreEqual(ExecutionState.Ready, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
45
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
46 comp.Start().Join(1000);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
47
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
48 Assert.AreEqual(ExecutionState.Running, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
49
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
50 comp.Stop().Join(1000);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
51
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
52 Assert.AreEqual(ExecutionState.Disposed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
53
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
54 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
55
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
56 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
57 public void InitFailTest() {
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
58 var comp = new MockRunnableComponent(false) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
59 MockInit = () => {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
60 throw new Exception("BAD");
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
61 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
62 };
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
63
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
64 ShouldThrow(() => comp.Start());
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
65 ShouldThrow(() => comp.Stop());
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
66 Assert.AreEqual(ExecutionState.Created, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
67
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
68 ShouldThrow(comp.Initialize);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
69
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
70 Assert.AreEqual(ExecutionState.Failed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
71
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
72 ShouldThrow(() => comp.Start());
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
73 ShouldThrow(() => comp.Stop());
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
74 Assert.AreEqual(ExecutionState.Failed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
75
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
76 comp.Dispose();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
77 Assert.AreEqual(ExecutionState.Disposed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
78 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
79
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
80 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
81 public void DisposedTest() {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
82
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
83 var comp = new MockRunnableComponent(false);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
84 comp.Dispose();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
85
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
86 ShouldThrow(() => comp.Start());
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
87 ShouldThrow(() => comp.Stop());
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
88 ShouldThrow(comp.Initialize);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
89
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
90 Assert.AreEqual(ExecutionState.Disposed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
91 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
92
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
93 [TestMethod]
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
94 public void ShouldCallDisposeOnStop() {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
95 var comp = new MockRunnableComponent(true);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
96
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
97 bool disposed = false;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
98 comp.MockDispose = (disposing, error) => {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
99 disposed = true;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
100 };
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
101
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
102 comp.Start().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
103 comp.Stop().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
104
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
105 ShouldThrow(() => comp.Start());
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
106 ShouldThrow(() => comp.Stop());
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
107 ShouldThrow(comp.Initialize);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
108
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
109 Assert.AreEqual(ExecutionState.Disposed, comp.State);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
110 Assert.IsTrue(disposed);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
111 }
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
112
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
113 [TestMethod]
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
114 public void ShouldNotCallDisposeOnStop() {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
115 var comp = new MockRunnableComponent(true, true);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
116
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
117 bool disposed = false;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
118 comp.MockDispose = (disposing, error) => {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
119 disposed = true;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
120 };
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
121
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
122 comp.Start().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
123 comp.Stop().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
124
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
125 Assert.AreEqual(ExecutionState.Ready, comp.State);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
126 Assert.IsFalse(disposed);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
127 }
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
128
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
129 [TestMethod]
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
130 public void SelfDisposeOnStop() {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
131 var comp = new MockRunnableComponent(true, true);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
132
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
133 bool disposed = false;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
134 Exception lastError = null;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
135 comp.MockDispose = (disposing, error) => {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
136 disposed = true;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
137 lastError = error;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
138 };
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
139
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
140 comp.Start().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
141 comp.Stop().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
142
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
143 Assert.AreEqual(ExecutionState.Ready, comp.State);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
144 Assert.IsFalse(disposed);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
145
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
146 comp.MockStop = () => {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
147 comp.Dispose();
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
148 return Promise.Success;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
149 };
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
150
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
151 comp.Start().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
152 comp.Stop().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
153
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
154 Assert.AreEqual(ExecutionState.Disposed, comp.State);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
155 Assert.IsTrue(disposed);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
156 }
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
157
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
158 [TestMethod]
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
159 public void StartCancelTest() {
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
160 var comp = new MockRunnableComponent(true) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
161 MockStart = () => PromiseHelper.Sleep(100000, 0)
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
162 };
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
163
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
164 var p = comp.Start();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
165 Assert.AreEqual(ExecutionState.Starting, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
166 p.Cancel();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
167 ShouldThrow(() => p.Join(1000));
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
168 Assert.AreEqual(ExecutionState.Failed, comp.State);
188
3071220371f8 Updated VS project
cin
parents: 185
diff changeset
169
194
d45bdf510514 working on diagnostics
cin
parents: 188
diff changeset
170 Assert.IsTrue(comp.LastError is OperationCanceledException);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
171
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
172 comp.Dispose();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
173 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
174
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
175 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
176 public void StartStopTest() {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
177 var stop = new Signal();
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
178 var comp = new MockRunnableComponent(true) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
179 MockStart = () => PromiseHelper.Sleep(100000, 0),
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
180 MockStop = () => AsyncPool.RunThread(stop.Wait)
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
181 };
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
182
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
183 var p1 = comp.Start();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
184 var p2 = comp.Stop();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
185 // should enter stopping state
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
186
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
187 ShouldThrow(p1.Join);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
188 Assert.IsTrue(p1.IsCancelled);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
189 Assert.AreEqual(ExecutionState.Stopping, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
190
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
191 stop.Set();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
192 p2.Join(1000);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
193 Assert.AreEqual(ExecutionState.Disposed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
194 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
195
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
196 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
197 public void StartStopFailTest() {
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
198 var comp = new MockRunnableComponent(true) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
199 MockStart = () => PromiseHelper.Sleep(100000, 0).Then(null,null,x => { throw new Exception("I'm dead"); })
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
200 };
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
201
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
202 comp.Start();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
203 var p = comp.Stop();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
204 // if Start fails to cancel, should fail to stop
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
205 ShouldThrow(() => p.Join(1000));
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
206 Assert.AreEqual(ExecutionState.Failed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
207 Assert.IsNotNull(comp.LastError);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
208 Assert.AreEqual("I'm dead", comp.LastError.Message);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
209 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
210
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
211 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
212 public void StopCancelTest() {
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
213 var comp = new MockRunnableComponent(true) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
214 MockStop = () => PromiseHelper.Sleep(100000, 0)
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
215 };
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
216
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
217 comp.Start();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
218 var p = comp.Stop();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
219 Assert.AreEqual(ExecutionState.Stopping, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
220 p.Cancel();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
221 ShouldThrow(() => p.Join(1000));
188
3071220371f8 Updated VS project
cin
parents: 185
diff changeset
222 Assert.AreEqual(ExecutionState.Failed, comp.State);
194
d45bdf510514 working on diagnostics
cin
parents: 188
diff changeset
223 Assert.IsTrue(comp.LastError is OperationCanceledException);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
224
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
225 comp.Dispose();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
226 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
227
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
228 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
229 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
230