Mercurial > pub > ImplabNet
diff Implab.Test/AsyncTests.cs @ 76:c761fc982e1d v2
Refactoring of the IPromise<T> interface
Added tests
author | cin |
---|---|
date | Wed, 10 Sep 2014 17:53:05 +0400 |
parents | 3b8393be3441 |
children | 91362ffbecf8 |
line wrap: on
line diff
--- a/Implab.Test/AsyncTests.cs Wed Sep 10 11:17:37 2014 +0400 +++ b/Implab.Test/AsyncTests.cs Wed Sep 10 17:53:05 2014 +0400 @@ -38,6 +38,38 @@ } [TestMethod] + public void CancelExceptionTest() { + var p = new Promise<bool>(); + p.Cancel(); + + var p2 = p.Cancelled(() => { + throw new ApplicationException("CANCELLED"); + }); + + try { + p2.Join(); + Assert.Fail(); + } catch (ApplicationException err) { + Assert.AreEqual("CANCELLED", err.InnerException.Message); + } + + } + + [TestMethod] + public void ContinueOnCancelTest() { + var p = new Promise<bool>(); + p.Cancel(); + + var p2 = p + .Cancelled(() => { + throw new ApplicationException("CANCELLED"); + }) + .Error(e => true); + + Assert.AreEqual(true, p2.Join()); + } + + [TestMethod] public void JoinSuccessTest() { var p = new Promise<int>(); p.Resolve(100); @@ -63,7 +95,7 @@ public void MapTest() { var p = new Promise<int>(); - var p2 = p.Map(x => x.ToString()); + var p2 = p.Then(x => x.ToString()); p.Resolve(100); Assert.AreEqual(p2.Join(), "100"); @@ -185,8 +217,8 @@ var stop = new ManualResetEvent(false); int total = 0; - int itemsPerWriter = 1000; - int writersCount = 3; + int itemsPerWriter = 10000; + int writersCount = 10; for (int i = 0; i < writersCount; i++) { Interlocked.Increment(ref writers); @@ -318,7 +350,7 @@ .Chain(x => PromiseHelper .Sleep(200, "Hi, " + x) - .Map(y => y) + .Then(y => y) .Cancelled(() => flags[1] = true) ) .Cancelled(() => flags[2] = true); @@ -341,7 +373,7 @@ // завершаться ошибкой OperationCanceledException var p = PromiseHelper .Sleep(1, "Hi, HAL!") - .Chain(x => { + .Then(x => { // запускаем две асинхронные операции var result = PromiseHelper.Sleep(1000, "HEM ENABLED!!!"); // вторая операция отменяет первую до завершения @@ -360,16 +392,15 @@ [TestMethod] public void ChainedCancel2Test() { // при отмене цепочки обещаний, вложенные операции также должны отменяться - IPromise p = null; var pSurvive = new Promise<bool>(); var hemStarted = new ManualResetEvent(false); - p = PromiseHelper + var p = PromiseHelper .Sleep(1, "Hi, HAL!") .Chain(x => { hemStarted.Set(); // запускаем две асинхронные операции var result = PromiseHelper - .Sleep(1000, "HEM ENABLED!!!") + .Sleep(10000, "HEM ENABLED!!!") .Then(s => pSurvive.Resolve(false)); result