From 0cc5d89199fa31702698c60895adc1264422ff58 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Sat, 28 Feb 2026 18:44:05 -0500 Subject: [PATCH] fix(tests): replace flaky sleep with retry loop in SubscriptionIndexTests Use a 2-second deadline retry loop instead of fixed Thread.Sleep(200) for async cache sweep verification, mirroring the Go test pattern. --- .../Internal/DataStructures/SubscriptionIndexTests.cs | 7 +++++-- reports/current.md | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/Internal/DataStructures/SubscriptionIndexTests.cs b/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/Internal/DataStructures/SubscriptionIndexTests.cs index cdbc26e..5ff7544 100644 --- a/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/Internal/DataStructures/SubscriptionIndexTests.cs +++ b/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/Internal/DataStructures/SubscriptionIndexTests.cs @@ -360,8 +360,11 @@ public class SubscriptionIndexTests for (int i = 0; i < 2 * SubscriptionIndex.SlCacheMax; i++) s.Match($"foo-{i}"); - // Cache sweep runs async, wait briefly. - Thread.Sleep(200); + // Cache sweep runs async; mirror Go test's retry window. + var deadline = DateTime.UtcNow + TimeSpan.FromSeconds(2); + while (DateTime.UtcNow < deadline && s.CacheCount() > SubscriptionIndex.SlCacheMax) + Thread.Sleep(10); + s.CacheCount().ShouldBeLessThanOrEqualTo(SubscriptionIndex.SlCacheMax); // Test wildcard cache update. diff --git a/reports/current.md b/reports/current.md index ef3e9f3..111f8da 100644 --- a/reports/current.md +++ b/reports/current.md @@ -1,6 +1,6 @@ # NATS .NET Porting Status Report -Generated: 2026-02-28 23:39:18 UTC +Generated: 2026-02-28 23:44:05 UTC ## Modules (12 total)