Skip to content

Commit

Permalink
Stabilize CanCancelOnRemoteTarget test
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Nov 6, 2019
1 parent 2de64c4 commit 50fe4b6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/StreamJsonRpc.Tests/JsonRpcRemoteTargetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ public async Task CanInvokeOnOriginServerFromAdditionalRemoteTarget()
public async Task CanCancelOnRemoteTarget()
{
var tokenSource = new CancellationTokenSource();
RemoteTargetOne.CancellableRemoteOperationEntered.Reset();
var task = this.originRpc.InvokeWithCancellationAsync<bool>(nameof(RemoteTargetOne.CancellableRemoteOperation), cancellationToken: tokenSource.Token);

// Don't cancel the token until we've entered the method, since the point is the RPC method receives the notice,
// not that we cancel before it's even transmitted.
await RemoteTargetOne.CancellableRemoteOperationEntered.WaitAsync(this.TimeoutToken);
tokenSource.Cancel();

var result = await task;
Assert.True(result);
}
Expand Down Expand Up @@ -280,6 +286,8 @@ public class RemoteTargetOne
{
private static TaskCompletionSource<int> notificationTcs = new TaskCompletionSource<int>();

internal static readonly AsyncManualResetEvent CancellableRemoteOperationEntered = new AsyncManualResetEvent();

public static Task<int> NotificationReceived => notificationTcs.Task;

public static void GetOne()
Expand All @@ -305,6 +313,7 @@ public static async Task<int> AddOneLongRunningAsync(int value)

public static async Task<bool> CancellableRemoteOperation(CancellationToken token)
{
CancellableRemoteOperationEntered.Set();
var retryIndex = 0;
while (retryIndex < 100)
{
Expand Down

0 comments on commit 50fe4b6

Please sign in to comment.