Mercurial > pub > ImplabNet
comparison Implab.Test/AsyncTests.cs @ 23:f0568ff069a5
Слияние с promises
author | cin |
---|---|
date | Wed, 13 Nov 2013 14:03:20 +0400 |
parents | 5a35900264f5 |
children | ee04e1fa78da |
comparison
equal
deleted
inserted
replaced
18:0c924dff5498 | 23:f0568ff069a5 |
---|---|
12 int res = -1; | 12 int res = -1; |
13 var p = new Promise<int>(); | 13 var p = new Promise<int>(); |
14 p.Then(x => res = x); | 14 p.Then(x => res = x); |
15 p.Resolve(100); | 15 p.Resolve(100); |
16 | 16 |
17 Assert.AreEqual(res, 100); | 17 Assert.AreEqual(100, res); |
18 } | 18 } |
19 | 19 |
20 [TestMethod] | 20 [TestMethod] |
21 public void RejectTest() { | 21 public void RejectTest() { |
22 int res = -1; | 22 int res = -1; |
99 | 99 |
100 [TestMethod] | 100 [TestMethod] |
101 public void WorkerPoolSizeTest() { | 101 public void WorkerPoolSizeTest() { |
102 var pool = new WorkerPool(5, 10, 0); | 102 var pool = new WorkerPool(5, 10, 0); |
103 | 103 |
104 Assert.AreEqual(5, pool.ThreadCount); | 104 Assert.AreEqual(5, pool.PoolSize); |
105 | 105 |
106 pool.Invoke(() => { Thread.Sleep(1000000); return 10; }); | 106 pool.Invoke(() => { Thread.Sleep(100000000); return 10; }); |
107 pool.Invoke(() => { Thread.Sleep(1000000); return 10; }); | 107 pool.Invoke(() => { Thread.Sleep(100000000); return 10; }); |
108 pool.Invoke(() => { Thread.Sleep(1000000); return 10; }); | 108 pool.Invoke(() => { Thread.Sleep(100000000); return 10; }); |
109 | 109 |
110 Assert.AreEqual(5, pool.ThreadCount); | 110 Assert.AreEqual(5, pool.PoolSize); |
111 | 111 |
112 for (int i = 0; i < 100; i++) | 112 for (int i = 0; i < 100; i++) |
113 pool.Invoke(() => { Thread.Sleep(1000000); return 10; }); | 113 pool.Invoke(() => { Thread.Sleep(100000000); return 10; }); |
114 Thread.Sleep(100); | 114 Thread.Sleep(200); |
115 Assert.AreEqual(10, pool.ThreadCount); | 115 Assert.AreEqual(10, pool.PoolSize); |
116 | 116 |
117 pool.Dispose(); | 117 pool.Dispose(); |
118 } | 118 } |
119 | 119 |
120 [TestMethod] | 120 [TestMethod] |
147 } | 147 } |
148 | 148 |
149 [TestMethod] | 149 [TestMethod] |
150 public void WorkerPoolDisposeTest() { | 150 public void WorkerPoolDisposeTest() { |
151 var pool = new WorkerPool(5, 20); | 151 var pool = new WorkerPool(5, 20); |
152 Assert.AreEqual(5, pool.ThreadCount); | 152 Assert.AreEqual(5, pool.PoolSize); |
153 pool.Dispose(); | 153 pool.Dispose(); |
154 Thread.Sleep(100); | 154 Thread.Sleep(500); |
155 Assert.AreEqual(0, pool.ThreadCount); | 155 Assert.AreEqual(0, pool.PoolSize); |
156 pool.Dispose(); | 156 pool.Dispose(); |
157 } | 157 } |
158 | 158 |
159 [TestMethod] | 159 [TestMethod] |
160 public void MTQueueTest() { | 160 public void MTQueueTest() { |
242 } | 242 } |
243 | 243 |
244 [TestMethod] | 244 [TestMethod] |
245 public void ChainedMapTest() { | 245 public void ChainedMapTest() { |
246 | 246 |
247 using (var pool = new WorkerPool(8,100,0)) { | 247 using (var pool = new WorkerPool(4,4,0)) { |
248 int count = 10000; | 248 int count = 10000; |
249 | 249 |
250 double[] args = new double[count]; | 250 double[] args = new double[count]; |
251 var rand = new Random(); | 251 var rand = new Random(); |
252 | 252 |