comparison Implab.Test/CancelationTests.cs @ 149:eb793fbbe4ea v2

fixed promises cancellation
author cin
date Wed, 06 May 2015 17:11:27 +0300
parents 706fccb85524
children cbe10ac0731e
comparison
equal deleted inserted replaced
148:e6d4b41f0101 149:eb793fbbe4ea
46 [TestMethod] 46 [TestMethod]
47 public void CancelActionBeforeStartTask() { 47 public void CancelActionBeforeStartTask() {
48 bool run = false; 48 bool run = false;
49 var task = new ActionTask(() => { 49 var task = new ActionTask(() => {
50 run = true; 50 run = true;
51 }, null, null); 51 }, null, null, true);
52 52
53 // request cancelation 53 // request cancelation
54 task.Cancel(); 54 task.Cancel();
55 Assert.IsTrue(task.IsCancelled); 55 Assert.IsTrue(task.IsCancelled);
56 task.Resolve(); 56 task.Resolve();
63 var started = new Signal(); 63 var started = new Signal();
64 64
65 var task = new ActionTask(() => { 65 var task = new ActionTask(() => {
66 started.Set(); 66 started.Set();
67 finish.Wait(); 67 finish.Wait();
68 }, null, null); 68 }, null, null, true);
69 69
70 AsyncPool.RunThread(() => { 70 AsyncPool.RunThread(() => {
71 task.Resolve(); 71 task.Resolve();
72 }); 72 });
73 73
83 83
84 } 84 }
85 85
86 [TestMethod] 86 [TestMethod]
87 public void CancelTaskChainFromBottom() { 87 public void CancelTaskChainFromBottom() {
88 var started = new Signal();
88 var check1 = new Signal(); 89 var check1 = new Signal();
89 var requested = false; 90 var requested = false;
90 var p1 = AsyncPool.RunThread(token => { 91 var p1 = AsyncPool.RunThread(token => {
91 token.CancellationRequested(reason => requested = true); 92 token.CancellationRequested(reason => requested = true);
93 started.Set();
92 check1.Wait(); 94 check1.Wait();
93 token.CancelOperationIfRequested(); 95 token.CancelOperationIfRequested();
94 }); 96 });
97
98 started.Wait();
95 99
96 var p2 = p1.Then(() => { 100 var p2 = p1.Then(() => {
97 }); 101 });
98 102
99 Assert.IsFalse(p1.IsResolved); 103 Assert.IsFalse(p1.IsResolved);