F6: test del ponte in rete affidabile sotto carico (#24)
TestClient.WaitUntil ingoiava il tempo scaduto con ContinueWith(_ => true): se il moto dell'ultimo tick non arrivava, il test proseguiva e confrontava un moto vecchio (scarto di 884 m nel rilascio v0.5.0). Ora lo scadere fa fallire il test, e la pausa si ripete finché coglie il treno in marcia, perché per un treno fermo il server non rimanda il moto. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
208faf625f
commit
640d4423d7
2 files changed
+28
-15
No files matched your search
@@ -102,8 +102,9 @@ public sealed class TestClient : IAsyncDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public Task<bool> WaitUntil(Func<bool> condition, string what, int timeoutMs = 60_000) =>
|
||||
WaitFor(() => condition() ? (object)true : null, what, timeoutMs).ContinueWith(_ => true);
|
||||
/// <summary>Come WaitFor; il tempo scaduto fa fallire il test (prima veniva ingoiato, #24).</summary>
|
||||
public async Task WaitUntil(Func<bool> condition, string what, int timeoutMs = 60_000) =>
|
||||
await WaitFor(() => condition() ? (object)true : null, what, timeoutMs);
|
||||
|
||||
/// <summary>Invia un comando e ne attende l'esito.</summary>
|
||||
public async Task<CommandResultMessage> Do(GameCommand command)
|
||||
@@ -185,19 +186,31 @@ public static class ServerTests
|
||||
await client.Ok(new AssignTrainCommand(new TrainId(train), new LineId(line)));
|
||||
await client.WaitUntil(() => w.Motions.TryGetValue(train, out var m) && m.Speed > 5, "treno in moto", 120_000);
|
||||
|
||||
// in pausa: la posizione disegnata dal client coincide con quella del server
|
||||
await client.Connection.SendAsync(new SetSpeed { Speed = 0 });
|
||||
// la pausa vale da quando il ciclo di gioco ha elaborato SetSpeed (sotto carico può tardare)
|
||||
for (int i = 0; i < 500 && server.Host.Speed != 0; i++) await Task.Delay(10);
|
||||
Assert.Equal((byte)0, server.Host.Speed);
|
||||
long tick;
|
||||
Vec2? head;
|
||||
while (true)
|
||||
// in pausa: la posizione disegnata dal client coincide con quella del server. La pausa
|
||||
// deve cogliere il treno in marcia: fermo (in stazione, a un segnale) il server non
|
||||
// rimanda il moto e il client ne tiene uno di un tick precedente (#24)
|
||||
long tick = 0;
|
||||
Vec2? head = null;
|
||||
for (int attempt = 0; ; attempt++)
|
||||
{
|
||||
(tick, head) = await server.Host.InvokeAsync(world => (world.Clock.Tick, Projection.HeadPoint(world, world.Trains[train])));
|
||||
await Task.Delay(60);
|
||||
long again = await server.Host.InvokeAsync(world => world.Clock.Tick);
|
||||
if (again == tick) break;
|
||||
await client.Connection.SendAsync(new SetSpeed { Speed = 0 });
|
||||
// la pausa vale da quando il ciclo di gioco ha elaborato SetSpeed (sotto carico può tardare)
|
||||
for (int i = 0; i < 500 && server.Host.Speed != 0; i++) await Task.Delay(10);
|
||||
Assert.Equal((byte)0, server.Host.Speed);
|
||||
float speed;
|
||||
while (true)
|
||||
{
|
||||
(tick, head, speed) = await server.Host.InvokeAsync(world =>
|
||||
(world.Clock.Tick, Projection.HeadPoint(world, world.Trains[train]), Projection.Motion(world, world.Trains[train])?.Speed ?? 0f));
|
||||
await Task.Delay(60);
|
||||
long again = await server.Host.InvokeAsync(world => world.Clock.Tick);
|
||||
if (again == tick) break;
|
||||
}
|
||||
if (speed > 0) break;
|
||||
Assert.True(attempt < 20, "in 20 pause il treno non era mai in marcia");
|
||||
await client.Connection.SendAsync(new SetSpeed { Speed = 8 });
|
||||
long paused = tick;
|
||||
await client.WaitUntil(() => w.Motions.TryGetValue(train, out var m) && m.Tick > paused && m.Speed > 0, "treno di nuovo in moto", 120_000);
|
||||
}
|
||||
// in pausa il server rimanda i moti dei treni in marcia ogni 100 ms
|
||||
await client.WaitUntil(() => w.Motions.TryGetValue(train, out var m) && m.Tick == tick, "moto all'ultimo tick", 10_000);
|
||||
|
||||
Reference in new issue
Block a user