Skip to content

Commit 27e5503

Browse files
committed
refactor: 精简单元测试
1 parent a85d35e commit 27e5503

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

test/UnitTest/Services/TcpSocketFactoryTest.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ public async Task ConnectAsync_Timeout()
6363
[Fact]
6464
public async Task ConnectAsync_Cancel()
6565
{
66-
var client = CreateClient();
66+
var client = CreateClient(optionConfigure: options =>
67+
{
68+
options.ConnectTimeout = 500;
69+
});
6770

6871
// 测试 ConnectAsync 方法连接取消逻辑
6972
var cst = new CancellationTokenSource();
@@ -74,12 +77,7 @@ public async Task ConnectAsync_Cancel()
7477
Assert.False(connect);
7578

7679
// 测试真正的连接被取消逻辑
77-
cst = new CancellationTokenSource();
78-
_ = Task.Run(async () =>
79-
{
80-
await Task.Delay(200);
81-
cst.Cancel();
82-
});
80+
cst = new CancellationTokenSource(200);
8381
connect = await client.ConnectAsync("localhost", 9999, cst.Token);
8482
Assert.False(connect);
8583
}

0 commit comments

Comments
 (0)