Skip to content

Commit 54d076d

Browse files
committed
修复连接错自己,导致无限卡住
1 parent 2aa98cb commit 54d076d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

.github/workflows/dotnet-core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
run: dotnet build --configuration Release
2424

2525
- name: Test
26-
run: dotnet test --configuration Release --no-build
26+
run: dotnet test --configuration Release -v:n --tl:off --no-build
2727

2828
- name: Pack
2929
run: dotnet pack --configuration Release --no-build

tests/dotnetCampus.Ipc.Tests/IpcProviderTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,21 @@ public async Task TestTryGetOrConnectExistsPeerAsync2()
2323
var ipcProvider2 = new IpcProvider();
2424
ipcProvider2.StartServer();
2525

26-
var result = await ipcProvider1.TryGetOrConnectExistsPeerAsync(peerName);
26+
var result = await ipcProvider2.TryGetOrConnectExistsPeerAsync(peerName).WaitAsync(TimeSpan.FromSeconds(5));
2727
Assert.IsTrue(result.IsSuccess);
2828
Assert.IsNotNull(result.PeerProxy);
2929
}
30+
31+
// 预期这一条是可能过也可能不过的,取决于时机,于是默认不加入单元测试去跑了
32+
// 尽管提供了 TryGetOrConnectExistsPeerAsync 方法,但仍然有一些边界的情况。正常也没有开发者会想着去连接自己吧
33+
//[TestMethod("使用 TryGetOrConnectExistsPeerAsync 尝试错误地连接自身,可能出现无限等待")]
34+
public async Task TestTryGetOrConnectExistsPeerAsync3()
35+
{
36+
var peerName = "The_Self_IpcProvider_E6EE8975-EF9A-480B-912D-B3C4530294E0";
37+
var ipcProvider1 = new IpcProvider(peerName);
38+
ipcProvider1.StartServer();
39+
40+
var result = await ipcProvider1.TryGetOrConnectExistsPeerAsync(peerName).WaitAsync(TimeSpan.FromSeconds(5));
41+
_ = result;
42+
}
3043
}

0 commit comments

Comments
 (0)