Mercurial > pub > ImplabNet
comparison Implab.Test/AsyncTests.cs @ 33:b255e4aeef17
removed the reference to the parent from the promise object this allows
resolved promises to release parents and results they are holding.
Added complete set of operations to IPromiseBase interface
Subscribing to the cancellation event of the promise should not affect it's
IsExclusive property
More tests.
author | cin |
---|---|
date | Thu, 10 Apr 2014 02:39:29 +0400 |
parents | 2fad2d1f4b03 |
children | dabf79fde388 |
comparison
equal
deleted
inserted
replaced
32:8eca2652d2ff | 33:b255e4aeef17 |
---|---|
326 | 326 |
327 Assert.IsFalse(flags[0]); | 327 Assert.IsFalse(flags[0]); |
328 Assert.IsTrue(flags[1]); | 328 Assert.IsTrue(flags[1]); |
329 Assert.IsTrue(flags[2]); | 329 Assert.IsTrue(flags[2]); |
330 } | 330 } |
331 | |
332 [TestMethod] | |
333 public void ChainedCancel1Test() { | |
334 // при отмене сцепленной асинхронной операции все обещание должно | |
335 // завершаться ошибкой OperationCanceledException | |
336 var p = PromiseHelper | |
337 .Sleep(1, "Hi, HAL!") | |
338 .Chain(x => { | |
339 // запускаем две асинхронные операции | |
340 var result = PromiseHelper.Sleep(1000, "HEM ENABLED!!!"); | |
341 // вторая операция отменяет первую до завершения | |
342 PromiseHelper | |
343 .Sleep(100, "HAL, STOP!") | |
344 .Then(() => result.Cancel()); | |
345 return result; | |
346 }); | |
347 try { | |
348 p.Join(); | |
349 } catch (TargetInvocationException err) { | |
350 Assert.IsTrue(err.InnerException is OperationCanceledException); | |
351 } | |
352 } | |
353 | |
354 [TestMethod] | |
355 public void ChainedCancel2Test() { | |
356 // при отмене цепочки обещаний, вложенные операции также должны отменяться | |
357 IPromiseBase p = null; | |
358 var pSurvive = new Promise<bool>(); | |
359 var hemStarted = new ManualResetEvent(false); | |
360 p = PromiseHelper | |
361 .Sleep(1, "Hi, HAL!") | |
362 .Chain(x => { | |
363 hemStarted.Set(); | |
364 // запускаем две асинхронные операции | |
365 var result = PromiseHelper | |
366 .Sleep(1000, "HEM ENABLED!!!") | |
367 .Then(s => pSurvive.Resolve(false)); | |
368 | |
369 result | |
370 .Cancelled(() => pSurvive.Resolve(true)); | |
371 | |
372 return result; | |
373 }); | |
374 | |
375 hemStarted.WaitOne(); | |
376 p.Cancel(); | |
377 | |
378 try { | |
379 p.Join(); | |
380 } catch (OperationCanceledException) { | |
381 Assert.IsTrue(pSurvive.Join()); | |
382 } | |
383 } | |
331 } | 384 } |
332 } | 385 } |
333 | 386 |