Skip to content

Commit 1558aaa

Browse files
committed
test: strengthen wizard request race coverage
Co-authored-by: Copilot App <[email protected]> Copilot-Session: ef1a489e-d0db-416e-a8da-ac6184e5f6af
1 parent e3dbbf8 commit 1558aaa

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

‎tests/OpenClaw.Shared.Tests/OpenClawGatewayClientTests.cs‎

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,12 @@ await server.SendTextAsync(
535535
}));
536536

537537
var payload = await responseTask.WaitAsync(TimeSpan.FromSeconds(2));
538-
client.Dispose();
539538

540539
Assert.Equal("welcome", payload.GetProperty("stepId").GetString());
541540
Assert.Equal((0, 0), helper.GetPendingRequestCounts());
541+
542+
client.Dispose();
543+
Assert.Equal((0, 0), helper.GetPendingRequestCounts());
542544
}
543545

544546
[Fact]
@@ -588,7 +590,55 @@ public async Task SendWizardRequestAsync_DeadlineExpires_ThrowsTimeoutAndCleansT
588590
var responseTask = client.SendWizardRequestAsync("wizard.status", timeoutMs: 250);
589591
await server.ReceiveTextAsync().WaitAsync(TimeSpan.FromSeconds(2));
590592

591-
await Assert.ThrowsAsync<TimeoutException>(async () => await responseTask);
593+
var exception = await Assert.ThrowsAsync<TimeoutException>(async () => await responseTask);
594+
595+
Assert.Equal("Timed out waiting for wizard.status response", exception.Message);
596+
Assert.Equal((0, 0), helper.GetPendingRequestCounts());
597+
}
598+
599+
[Fact]
600+
public async Task SendWizardRequestAsync_LateResponseAfterTimeout_DoesNotChangeOutcomeOrTracking()
601+
{
602+
using var server = new LoopbackWebSocketServer();
603+
using var identity = new TempDirectory("wizard-request-");
604+
await server.StartAsync();
605+
var helper = new GatewayClientTestHelper(
606+
gatewayUrl: server.WebSocketUrl,
607+
identityPath: identity.Path);
608+
using var client = helper.Client;
609+
await client.ConnectAsync();
610+
611+
var timedOutTask = client.SendWizardRequestAsync("wizard.status", timeoutMs: 250);
612+
var timedOutRequest = await server.ReceiveTextAsync().WaitAsync(TimeSpan.FromSeconds(2));
613+
var timedOutRequestId = ReadRequestId(timedOutRequest);
614+
var firstTimeout = await Assert.ThrowsAsync<TimeoutException>(async () => await timedOutTask);
615+
616+
await server.SendTextAsync(
617+
JsonSerializer.Serialize(new
618+
{
619+
type = "res",
620+
id = timedOutRequestId,
621+
ok = true,
622+
payload = new { stepId = "too-late" }
623+
}));
624+
625+
var probeTask = client.SendWizardRequestAsync("wizard.status", timeoutMs: 10_000);
626+
var probeRequest = await server.ReceiveTextAsync().WaitAsync(TimeSpan.FromSeconds(2));
627+
var probeRequestId = ReadRequestId(probeRequest);
628+
await server.SendTextAsync(
629+
JsonSerializer.Serialize(new
630+
{
631+
type = "res",
632+
id = probeRequestId,
633+
ok = true,
634+
payload = new { stepId = "probe" }
635+
}));
636+
637+
var probePayload = await probeTask.WaitAsync(TimeSpan.FromSeconds(2));
638+
var repeatedTimeout = await Assert.ThrowsAsync<TimeoutException>(async () => await timedOutTask);
639+
640+
Assert.Equal("probe", probePayload.GetProperty("stepId").GetString());
641+
Assert.Same(firstTimeout, repeatedTimeout);
592642
Assert.Equal((0, 0), helper.GetPendingRequestCounts());
593643
}
594644

0 commit comments

Comments
 (0)