Skip to content

Commit

Permalink
Fix DisposeTriggersRequestAborted test.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmds authored Apr 18, 2024
1 parent 3c7b318 commit 51e6dca
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/Tmds.DBus.Protocol.Tests/ConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public async Task DisconnectedException()
[Fact]
public async Task DisposeTriggersRequestAborted()
{
TimeSpan timeout = TimeSpan.FromSeconds(30);

var connections = PairedConnection.CreatePair();
using var conn1 = connections.Item1;
using var conn2 = connections.Item2;
Expand All @@ -52,11 +54,13 @@ public async Task DisposeTriggersRequestAborted()

Task pendingCall = conn1.CallMethodAsync(CreateMessage());

await handler.WaitForRequestReceivedAsync().WaitAsync(timeout);

conn2.Dispose();

await Assert.ThrowsAsync<DisconnectedException>(() => pendingCall);

await handler.WaitForCancelledAsync().WaitAsync(new CancellationTokenSource(TimeSpan.FromSeconds(30)).Token);
await handler.WaitForCancelledAsync().WaitAsync(timeout);

MessageBuffer CreateMessage()
{
Expand Down Expand Up @@ -420,9 +424,11 @@ class WaitForCancellationHandler : IMethodHandler
public string Path => "/";

private readonly TaskCompletionSource _cancelled = new();
private readonly TaskCompletionSource _requestReceived = new();

public async ValueTask HandleMethodAsync(MethodContext context)
{
_requestReceived.TrySetResult();
try
{
while (true)
Expand All @@ -438,6 +444,8 @@ public async ValueTask HandleMethodAsync(MethodContext context)
}
}

public Task WaitForRequestReceivedAsync() => _requestReceived.Task;

public Task WaitForCancelledAsync() => _cancelled.Task;

public bool RunMethodHandlerSynchronously(Message message)
Expand Down

0 comments on commit 51e6dca

Please sign in to comment.