From da588f6bcc4c72ed5a7db6274641defdc43a9bc4 Mon Sep 17 00:00:00 2001 From: Geoff Battye Date: Mon, 9 Nov 2026 11:08:24 +1100 Subject: [PATCH] Wait for polling connection close to be observed in ConnectionObserverFixture The server completes the failed request before it releases the connection lease, so the 1 -> 0 count change can be recorded after the client's SayHelloAsync has already returned. Retry the assertion as the final close check already does. Fixes LEV-2276 Co-Authored-By: Claude Opus 5.5 --- .../Observability/ConnectionObserverFixture.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source/Halibut.Tests/Transport/Observability/ConnectionObserverFixture.cs b/source/Halibut.Tests/Transport/Observability/ConnectionObserverFixture.cs index 38cf50e2..8b5e36e5 100644 --- a/source/Halibut.Tests/Transport/Observability/ConnectionObserverFixture.cs +++ b/source/Halibut.Tests/Transport/Observability/ConnectionObserverFixture.cs @@ -76,10 +76,14 @@ public async Task ConnectionsCountForAPollingSubscriptionChangesOneConnectionAtA await Try.CatchingError(() => echo.SayHelloAsync("hello")); - var closeFirstConnection = connectionsObserver.ConnectionsCountChangedForSubscription.Skip(1).First(); - closeFirstConnection.PreviousCount.Should().Be(1); - closeFirstConnection.CurrentCount.Should().Be(0); - closeFirstConnection.SubscriptionId.Should().Be(clientAndService.ServiceUri); + // The failed request is completed before the server releases the connection lease, so the close may not be observed yet. + Wait.UntilActionSucceeds(() => + { + var closeFirstConnection = connectionsObserver.ConnectionsCountChangedForSubscription.Skip(1).First(); + closeFirstConnection.PreviousCount.Should().Be(1); + closeFirstConnection.CurrentCount.Should().Be(0); + closeFirstConnection.SubscriptionId.Should().Be(clientAndService.ServiceUri); + }, TimeSpan.FromSeconds(30), Logger, CancellationToken); await echo.SayHelloAsync("hello");