Skip to content

Commit

Permalink
Added cancellations for the server failing to start.
Browse files Browse the repository at this point in the history
  • Loading branch information
DJGosnell committed Aug 24, 2023
1 parent 84af107 commit 508135e
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/NexNet.IntegrationTests/BasePipeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TaskCompletionSource tcs
var (server, sNexus, client, cNexus) = CreateServerClient(
CreateServerConfig(type, log),
CreateClientConfig(type, log));
await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);
return (server, sNexus, client, cNexus, tcs);
}
Expand Down
36 changes: 18 additions & 18 deletions src/NexNet.IntegrationTests/NexusClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task NexusFiresOnConnected(Type type)
return ValueTask.CompletedTask;
};

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

await tcs.Task.Timeout(1);
Expand All @@ -47,7 +47,7 @@ public async Task ConnectsToServer(Type type)

clientConfig.InternalOnClientConnect = () => tcs.SetResult();

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

await tcs.Task.Timeout(1);
Expand Down Expand Up @@ -95,7 +95,7 @@ public async Task ConnectsAndDisconnectsMultipleTimesFromServer(Type type)
CreateServerConfig(type),
CreateClientConfig(type));

await server.StartAsync();
await server.StartAsync().Timeout(1);

for (int i = 0; i < 5; i++)
{
Expand Down Expand Up @@ -131,7 +131,7 @@ public async Task ClientProvidesAuthenticationToken(Type type)
CreateServerConfig(type),
clientConfig);

await server.StartAsync();
await server.StartAsync().Timeout(1);

clientConfig.Authenticate = () => new byte[] { 123 };
clientConfig.InternalOnSend= (_, bytes) =>
Expand Down Expand Up @@ -164,7 +164,7 @@ public async Task ClientSendsPing(Type type)
CreateServerConfig(type),
clientConfig);

await server.StartAsync();
await server.StartAsync().Timeout(1);

clientConfig.InternalOnSend = (_, bytes) =>
{
Expand Down Expand Up @@ -197,7 +197,7 @@ public async Task ClientResumePingOnDisconnect(Type type)
tcs.SetResult();
};

await server.StartAsync();
await server.StartAsync().Timeout(1);

await client.ConnectAsync().Timeout(1);
await client.DisconnectAsync().Timeout(1);
Expand Down Expand Up @@ -229,14 +229,14 @@ public async Task ReconnectsOnDisconnect(Type type)
serverConfig.InternalNoLingerOnShutdown = true;
serverConfig.InternalForceDisableSendingDisconnectSignal = true;

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);
await server.StopAsync();

// Wait for the client to process the disconnect.
await Task.Delay(50);

await server.StartAsync();
await server.StartAsync().Timeout(1);

await tcs.Task.Timeout(5);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ public async Task ReconnectsOnTimeout(Type type)
clientConfig.PingInterval = 75;
clientConfig.Timeout = 50;

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

await tcs.Task.Timeout(1);
Expand All @@ -293,7 +293,7 @@ public async Task ReconnectsNotifiesReconnecting(Type type)
serverConfig.InternalNoLingerOnShutdown = true;
serverConfig.InternalForceDisableSendingDisconnectSignal = true;

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);
await server.StopAsync();

Expand Down Expand Up @@ -328,7 +328,7 @@ public async Task ReconnectsStopsAfterSpecifiedTimes(Type type)
serverConfig.InternalNoLingerOnShutdown = true;
serverConfig.InternalForceDisableSendingDisconnectSignal = true;

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

await Task.Delay(100);
Expand Down Expand Up @@ -371,7 +371,7 @@ public async Task ClientProxyInvocationCancelsOnDisconnect(Type type)
}
};

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

await Task.Delay(100);
Expand All @@ -389,7 +389,7 @@ public async Task ReadyTaskCompletesUponConnection(Type type)
CreateServerConfig(type),
CreateClientConfig(type));

await server.StartAsync();
await server.StartAsync().Timeout(1);

await client.ConnectAsync().Timeout(1);
}
Expand All @@ -414,7 +414,7 @@ public async Task ReadyTaskCompletesUponAuthentication(Type type)
return ValueTask.FromResult<IIdentity?>(new DefaultIdentity());
};

await server.StartAsync();
await server.StartAsync().Timeout(1);

await client.ConnectAsync().Timeout(1);
Assert.IsTrue(authCompleted);
Expand All @@ -435,7 +435,7 @@ public async Task ReadyTaskCompletesUponAuthFailure(Type type)

serverHub.OnAuthenticateEvent = hub => ValueTask.FromResult<IIdentity?>(null);

await server.StartAsync();
await server.StartAsync().Timeout(1);

await client.ConnectAsync().Timeout(1);
Assert.AreEqual(ConnectionState.Disconnected, client.State);
Expand All @@ -453,7 +453,7 @@ public async Task DisconnectTaskCompletesUponDisconnection(Type type)

serverHub.OnAuthenticateEvent = hub => ValueTask.FromResult<IIdentity?>(null);

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);
var disconnectTask = client.DisconnectedTask;

Expand All @@ -479,7 +479,7 @@ public async Task DisconnectTaskCompletesUponAuthFailure(Type type)

serverHub.OnAuthenticateEvent = hub => ValueTask.FromResult<IIdentity?>(null);

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);
await client.DisconnectedTask.Timeout(1);

Expand All @@ -498,7 +498,7 @@ public async Task DisconnectTaskCompletesAfterDisconnect(Type type)

serverHub.OnAuthenticateEvent = hub => ValueTask.FromResult<IIdentity?>(null);

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

await server.StopAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private async Task<Task> ClientSendsMessage<T>(Type type, Action<ServerNexus> se

setup.Invoke(serverNexus);

await server.StartAsync();
await server.StartAsync().Timeout(1);

clientConfig.InternalOnSend = (_, bytes) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task ClientThrowsWhenArgumentTooLarge(Type type)
CreateServerConfig(type),
CreateClientConfig(type));

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

var data = new byte[65521];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public async Task Client_PipeNotifiesWhenReady(Type type)
[TestCase(Type.Quic)]
public async Task Client_PipeReadyCancelsOnDisconnection(Type type)
{
var (server, _, client, _, _) = await Setup(type, true);
var (server, _, client, _, _) = await Setup(type);

var pipe = client.CreatePipe();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private async Task ClientReceivesInvocation(Type type, Action<ServerNexus, Clien
CreateServerConfig(type),
CreateClientConfig(type));

await server.StartAsync();
await server.StartAsync().Timeout(1);

action(serverNexus, clientNexus, tcs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private async Task InvokeFromClientAndVerifySent(Type type, InvocationMessage ex
CreateServerConfig(type),
clientConfig);

await server.StartAsync();
await server.StartAsync().Timeout(1);

clientConfig.InternalOnSend = (_, bytes) =>
{
Expand Down
8 changes: 4 additions & 4 deletions src/NexNet.IntegrationTests/NexusServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task AcceptsClientConnection(Type type)

serverConfig.InternalOnConnect = () => tcs.SetResult();

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

await tcs.Task.Timeout(1);
Expand All @@ -44,7 +44,7 @@ public async Task NexusFiresOnConnected(Type type)
return ValueTask.CompletedTask;
};

await server.StartAsync();
await server.StartAsync().Timeout(1);

await client.ConnectAsync().Timeout(1);

Expand All @@ -68,7 +68,7 @@ public async Task StartsAndStopsMultipleTimes(Type type)

for (int i = 0; i < 5; i++)
{
await server.StartAsync();
await server.StartAsync().Timeout(1);

await client.ConnectAsync().Timeout(1);

Expand All @@ -93,7 +93,7 @@ public async Task StopsAndReleasesStoppedTcs(Type type)


Assert.IsNull(server.StoppedTask);
await server.StartAsync();
await server.StartAsync().Timeout(1);
Assert.IsFalse(server.StoppedTask!.IsCompleted);

await server.StopAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private async Task<Task> ServerSendsMessage<T>(Type type, Action<ClientNexus> se

setup.Invoke(clientNexus);

await server.StartAsync();
await server.StartAsync().Timeout(1);

serverConfig.InternalOnSend = (_, bytes) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task Server_PipeReaderReceivesDataMultipleTimes(Type type)
int count = 0;

// Ensure that the ids will properly wrap around.
const int iterations = 400;
const int iterations = 20;
sNexus.ServerTaskValueWithDuplexPipeEvent = async (nexus, pipe) =>
{
var result = await pipe.Input.ReadAsync();
Expand Down
20 changes: 10 additions & 10 deletions src/NexNet.IntegrationTests/NexusServerTests_NexusInvocations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task InvokesViaNexusContext(Type type)
#pragma warning disable CS1998
clientNexus.ClientTaskEvent = async _ => tcs.SetResult();
#pragma warning restore CS1998
await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

using var context = server.GetContext();
Expand Down Expand Up @@ -51,7 +51,7 @@ public async Task InvokesViaNexusContextAndDoesNotBlock(Type type)
return ValueTask.CompletedTask;
};

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

using var context = server.GetContext();
Expand Down Expand Up @@ -95,7 +95,7 @@ public async Task InvokesViaNexusAndDoesNotBlock(Type type)
completed = true;
};

await server.StartAsync();
await server.StartAsync().Timeout(1);

await client.ConnectAsync().Timeout(1);

Expand All @@ -115,7 +115,7 @@ public async Task InvokesViaNexusContextAndGetsReturnFromSingleClient(Type type)

clientNexus.ClientTaskValueEvent = _ => ValueTask.FromResult(54321);

await server.StartAsync();
await server.StartAsync().Timeout(1);
await client.ConnectAsync().Timeout(1);

using var context = server.GetContext();
Expand Down Expand Up @@ -153,7 +153,7 @@ public async Task NexusInvokesOnAll(Type type)
clientNexus1.ClientTaskEvent = async _ => tcs1.TrySetResult();
clientNexus2.ClientTaskEvent = async _ => tcs2.TrySetResult();
#pragma warning restore CS1998
await server.StartAsync();
await server.StartAsync().Timeout(1);

await client1.ConnectAsync().Timeout(1);
await client2.ConnectAsync().Timeout(1);
Expand Down Expand Up @@ -190,7 +190,7 @@ public async Task NexusInvokesOnGroup(Type type)
clientNexus1.ClientTaskEvent = async _ => tcs1.TrySetResult();
clientNexus2.ClientTaskEvent = async _ => tcs2.TrySetResult();
#pragma warning restore CS1998
await server.StartAsync();
await server.StartAsync().Timeout(1);

await client1.ConnectAsync().Timeout(1);
await client2.ConnectAsync().Timeout(1);
Expand Down Expand Up @@ -230,7 +230,7 @@ public async Task NexusInvokesOnGroups(Type type)
clientNexus1.ClientTaskEvent = async _ => tcs1.TrySetResult();
clientNexus2.ClientTaskEvent = async _ => tcs2.TrySetResult();
#pragma warning restore CS1998
await server.StartAsync();
await server.StartAsync().Timeout(1);

await client1.ConnectAsync().Timeout(1);
await client2.ConnectAsync().Timeout(1);
Expand Down Expand Up @@ -269,7 +269,7 @@ public async Task NexusInvokesOnOthers(Type type)
clientNexus1.ClientTaskEvent = async _ => invocationCount++;
clientNexus2.ClientTaskEvent = async _ => invocationCount++;
#pragma warning restore CS1998
await server.StartAsync();
await server.StartAsync().Timeout(1);

await client1.ConnectAsync().Timeout(1);
await client2.ConnectAsync().Timeout(1);
Expand Down Expand Up @@ -309,7 +309,7 @@ public async Task NexusInvokesOnClient(Type type)
clientNexus1.ClientTaskEvent = async _ => invocationCount++;
clientNexus2.ClientTaskEvent = async _ => invocationCount++;
#pragma warning restore CS1998
await server.StartAsync();
await server.StartAsync().Timeout(1);

await client1.ConnectAsync().Timeout(1);
await client2.ConnectAsync().Timeout(1);
Expand Down Expand Up @@ -349,7 +349,7 @@ public async Task NexusInvokesOnClients(Type type)
clientNexus1.ClientTaskEvent = async _ => tcs1.TrySetResult();
clientNexus2.ClientTaskEvent = async _ => tcs2.TrySetResult();
#pragma warning restore CS1998
await server.StartAsync();
await server.StartAsync().Timeout(1);

await client1.ConnectAsync().Timeout(1);
await client2.ConnectAsync().Timeout(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private async Task ServerReceivesInvocation(Type type, Action<ServerNexus, Clien
CreateServerConfig(type),
CreateClientConfig(type));

await server.StartAsync();
await server.StartAsync().Timeout(1);

action(serverNexus, clientNexus, tcs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private async Task InvokeFromServerAndVerifySent(Type type, InvocationMessage ex
var tcs = new TaskCompletionSource();
var (server, serverNexus, client, clientNexus) = CreateServerClient(serverConfig, clientConfig);

await server.StartAsync();
await server.StartAsync().Timeout(1);

serverConfig.InternalOnSend = (_, bytes) =>
{
Expand Down

0 comments on commit 508135e

Please sign in to comment.