Mercurial > pub > ImplabNet
diff Implab.Test/AsyncTests.cs @ 13:b0feb5b9ad1c promises
small fixes, WorkerPool still incomplete
author | cin |
---|---|
date | Wed, 06 Nov 2013 01:07:55 +0400 |
parents | 6ec82bf68c8e |
children | e943453e5039 |
line wrap: on
line diff
--- a/Implab.Test/AsyncTests.cs Tue Nov 05 19:55:34 2013 +0400 +++ b/Implab.Test/AsyncTests.cs Wed Nov 06 01:07:55 2013 +0400 @@ -107,6 +107,36 @@ } [TestMethod] + public void WorkerPoolSizeTest() { + var pool = new WorkerPool(5,10); + + Assert.AreEqual(5, pool.ThreadCount); + + pool.Invoke(() => { Thread.Sleep(1000); return 10; }); + pool.Invoke(() => { Thread.Sleep(1000); return 10; }); + pool.Invoke(() => { Thread.Sleep(1000); return 10; }); + + Assert.AreEqual(5, pool.ThreadCount); + + for (int i = 0; i < 100; i++) + pool.Invoke(() => { Thread.Sleep(1000); return 10; }); + Assert.AreEqual(10, pool.ThreadCount); + } + + [TestMethod] + public void WorkerPoolCorrectTest() { + var pool = new WorkerPool(5, 20); + + var count = 0; + for (int i = 0; i < 1000; i++) + pool + .Invoke(() => 1) + .Then(x => Interlocked.Add(ref count, x)); + + Assert.AreEqual(1000, count); + } + + [TestMethod] public void ComplexCase1Test() { var flags = new bool[3];