Skip to content

Commit 19c516f

Browse files
EvangelinkCopilot
andauthored
Stabilize MTP disconnect and controller-host tests (#12252)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent dd32241 commit 19c516f

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎test/UnitTests/Microsoft.Testing.Platform.UnitTests/Hosts/ControllerHostFixture.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ namespace Microsoft.Testing.Platform.UnitTests;
3232
[UnsupportedOSPlatform("browser")]
3333
internal sealed class ControllerHostFixture : IDisposable
3434
{
35-
public static readonly TimeSpan OperationLimit = TimeSpan.FromSeconds(30);
35+
public static readonly TimeSpan OperationLimit = TimeoutHelper.DefaultHangTimeSpanTimeout;
3636
private static readonly TimeSpan CleanupLimit = TimeSpan.FromSeconds(30);
37-
private readonly CancellationTokenSource _peerLifetime = new(OperationLimit);
37+
// The run guard owns the deadline; only teardown should cancel the protocol peer.
38+
private readonly CancellationTokenSource _peerLifetime = new();
3839
private readonly TaskCompletionSource<bool> _started = new(TaskCreationOptions.RunContinuationsAsynchronously);
3940
private readonly TaskCompletionSource<bool> _exited = new(TaskCreationOptions.RunContinuationsAsynchronously);
4041
private readonly ConcurrentQueue<Task> _workers = new();

‎test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/IPCTests.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ .. BitConverter.GetBytes(42),
358358
await requestReceived.Task.TimeoutAfterAsync(TimeoutHelper.DefaultHangTimeSpanTimeout);
359359
Assert.AreEqual(new IntMessage(42), await requestReceived.Task);
360360
client.Dispose();
361+
362+
// Observe transport EOF while the reply is gated, rather than racing the peer's handle closure.
363+
Task<int> disconnectTask = server.GetServerStream().ReadAsync(new byte[1], 0, 1, _testContext.CancellationToken);
364+
await disconnectTask.TimeoutAfterAsync(TimeoutHelper.DefaultHangTimeSpanTimeout);
365+
Assert.AreEqual(0, await disconnectTask);
361366
releaseResponse.TrySetResult(true);
362367

363368
await loggedMessage.Task.TimeoutAfterAsync(TimeoutHelper.DefaultHangTimeSpanTimeout);

0 commit comments

Comments
 (0)