Skip to content

Commit a184759

Browse files
committed
加上测试
1 parent 6681c1d commit a184759

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using dotnetCampus.Threading.Reentrancy;
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
using MSTest.Extensions.Contracts;
7+
8+
namespace AsyncWorkerCollection.Tests.Reentrancy
9+
{
10+
[TestClass]
11+
public class QueueReentrancyTaskTests
12+
{
13+
[ContractTestCase]
14+
public void InvokeAsync()
15+
{
16+
"并发执行大量任务,最终返回值按顺序获取到。".Test(async () =>
17+
{
18+
// Arrange
19+
var concurrentCount = 100;
20+
var resultList = new List<int>();
21+
var reentrancy = new QueueReentrancyTask<int, int>(async i =>
22+
{
23+
await Task.Delay(10).ConfigureAwait(false);
24+
resultList.Add(i);
25+
return i;
26+
});
27+
28+
// Action
29+
await Task.WhenAll(Enumerable.Range(0, concurrentCount).Select(i => reentrancy.InvokeAsync(i)));
30+
31+
// Assert
32+
for (var i = 0; i < concurrentCount; i++)
33+
{
34+
Assert.AreEqual(i, resultList[i]);
35+
}
36+
});
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)