Skip to content

Commit

Permalink
Fix test runner crash
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed May 7, 2024
1 parent aaf2c14 commit fb9ed53
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/StreamJsonRpc.Tests/JsonRpcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2969,6 +2969,11 @@ public void JoinableTaskFactory_IntegrationClientSideOnly_ManyConnections_Unique
// Set up a main thread and JoinableTaskContext.
JoinableTaskContext jtc = new();

// Track our async work so our test doesn't exit before our UI thread requests do,
// or the test process will crash.
JoinableTaskCollection jtCollection = jtc.CreateCollection();
JoinableTaskFactory jtf = jtc.CreateFactory(jtCollection);

// Configure the client (only) to understand JTF.
this.clientRpc.AllowModificationWhileListening = true;
this.clientRpc.JoinableTaskFactory = jtc.Factory;
Expand Down Expand Up @@ -2997,7 +3002,7 @@ public void JoinableTaskFactory_IntegrationClientSideOnly_ManyConnections_Unique
const string CallbackMethodName = "ClientNeedsMainThread";
alternateClientRpc.AddLocalRpcMethod(CallbackMethodName, new Func<Task>(async delegate
{
await jtc.Factory.SwitchToMainThreadAsync();
await jtf.SwitchToMainThreadAsync();
}));

alternateServerRpc.StartListening();
Expand All @@ -3007,6 +3012,9 @@ public void JoinableTaskFactory_IntegrationClientSideOnly_ManyConnections_Unique
{
await Assert.ThrowsAsync<OperationCanceledException>(() => this.clientRpc.InvokeWithCancellationAsync(nameof(this.server.CallbackOnAnotherConnection), new object?[] { CallbackMethodName }, this.TimeoutToken).WithCancellation(ExpectedTimeoutToken));
});

// Drain any UI thread requests before exiting the test.
jtc.Factory.Run(jtCollection.JoinTillEmptyAsync);
}

[Fact]
Expand Down

0 comments on commit fb9ed53

Please sign in to comment.