comparison 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
comparison
equal deleted inserted replaced
12:eb418ba8275b 13:b0feb5b9ad1c
105 105
106 Assert.AreNotEqual (pid, p.Join ()); 106 Assert.AreNotEqual (pid, p.Join ());
107 } 107 }
108 108
109 [TestMethod] 109 [TestMethod]
110 public void WorkerPoolSizeTest() {
111 var pool = new WorkerPool(5,10);
112
113 Assert.AreEqual(5, pool.ThreadCount);
114
115 pool.Invoke(() => { Thread.Sleep(1000); return 10; });
116 pool.Invoke(() => { Thread.Sleep(1000); return 10; });
117 pool.Invoke(() => { Thread.Sleep(1000); return 10; });
118
119 Assert.AreEqual(5, pool.ThreadCount);
120
121 for (int i = 0; i < 100; i++)
122 pool.Invoke(() => { Thread.Sleep(1000); return 10; });
123 Assert.AreEqual(10, pool.ThreadCount);
124 }
125
126 [TestMethod]
127 public void WorkerPoolCorrectTest() {
128 var pool = new WorkerPool(5, 20);
129
130 var count = 0;
131 for (int i = 0; i < 1000; i++)
132 pool
133 .Invoke(() => 1)
134 .Then(x => Interlocked.Add(ref count, x));
135
136 Assert.AreEqual(1000, count);
137 }
138
139 [TestMethod]
110 public void ComplexCase1Test() { 140 public void ComplexCase1Test() {
111 var flags = new bool[3]; 141 var flags = new bool[3];
112 142
113 // op1 (aync 200ms) => op2 (async 200ms) => op3 (sync map) 143 // op1 (aync 200ms) => op2 (async 200ms) => op3 (sync map)
114 144