test(comm): de-race StreamRelay null-map + SiteConnectionUp gauge under load (#288)
This commit is contained in:
@@ -386,15 +386,23 @@ public class SiteStreamGrpcServerTests : TestKit
|
||||
// While the stream is up the gauge is one above whatever baseline other
|
||||
// (possibly parallel) tests left behind — read relative so the assertion
|
||||
// is robust to test interleaving on the process-wide static counter.
|
||||
Assert.Equal(baseline + 1, ReadGauge());
|
||||
//
|
||||
// SiteConnectionOpened() runs AFTER the _activeStreams insertion that
|
||||
// WaitForConditionAsync(ActiveStreamCount == 1) keys off (see
|
||||
// SiteStreamGrpcServer.SubscribeInstance), so a one-shot ReadGauge() here
|
||||
// can race the increment under full-suite CPU oversubscription. Poll the
|
||||
// gauge with a generous timeout until it reaches baseline + 1.
|
||||
AwaitAssert(() => Assert.Equal(baseline + 1, ReadGauge()), TimeSpan.FromSeconds(5));
|
||||
|
||||
cts.Cancel();
|
||||
await streamTask;
|
||||
await WaitForConditionAsync(() => server.ActiveStreamCount == 0);
|
||||
|
||||
// After the cancel path runs the finally, the gauge is balanced back to
|
||||
// the baseline — no leaked "up" count.
|
||||
Assert.Equal(baseline, ReadGauge());
|
||||
// the baseline — no leaked "up" count. Poll here too: the gauge decrement
|
||||
// and the stream-count drop are independent observations, so under load
|
||||
// give the finally's SiteConnectionClosed() time to land.
|
||||
AwaitAssert(() => Assert.Equal(baseline, ReadGauge()), TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user