docs: add XML doc comments to server types and fix flaky test timings
Add XML doc comments to public properties across EventTypes, Connz, Varz, NatsOptions, StreamConfig, IStreamStore, FileStore, MqttListener, MqttSessionStore, MessageTraceContext, and JetStreamApiResponse. Fix flaky tests by increasing timing margins (ResponseTracker expiry 1ms→50ms, sleep 50ms→200ms) and document known flaky test patterns in tests.md.
This commit is contained in:
@@ -1160,11 +1160,11 @@ public sealed class FileStoreGoParityTests : IDisposable
|
||||
store.StoreMsg("foo", null, "1"u8.ToArray(), 0); // seq 1
|
||||
|
||||
// A small sleep so timestamps are distinct.
|
||||
System.Threading.Thread.Sleep(10);
|
||||
System.Threading.Thread.Sleep(50);
|
||||
var t2 = DateTime.UtcNow;
|
||||
store.StoreMsg("foo", null, "2"u8.ToArray(), 0); // seq 2
|
||||
|
||||
System.Threading.Thread.Sleep(10);
|
||||
System.Threading.Thread.Sleep(50);
|
||||
var t3 = DateTime.UtcNow;
|
||||
store.StoreMsg("foo", null, "3"u8.ToArray(), 0); // seq 3
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
using System.Text;
|
||||
using NATS.Server.JetStream.Models;
|
||||
using NATS.Server.JetStream.Storage;
|
||||
using NATS.Server.TestUtilities;
|
||||
|
||||
namespace NATS.Server.JetStream.Tests.JetStream.Storage;
|
||||
|
||||
@@ -335,7 +336,7 @@ public sealed class FileStoreTombstoneTests : IDisposable
|
||||
// After restart the message should still be present (not yet expired),
|
||||
// and after waiting 2 seconds it should expire.
|
||||
[Fact]
|
||||
public void MessageTTL_RecoverSingleMessageWithoutStreamState()
|
||||
public async Task MessageTTL_RecoverSingleMessageWithoutStreamState()
|
||||
{
|
||||
var dir = UniqueDir("ttl-recover");
|
||||
var opts = new FileStoreOptions { Directory = dir, MaxAgeMs = 1000 };
|
||||
@@ -358,8 +359,8 @@ public sealed class FileStoreTombstoneTests : IDisposable
|
||||
ss.LastSeq.ShouldBe(1UL);
|
||||
ss.Msgs.ShouldBe(1UL);
|
||||
|
||||
// Wait for TTL to expire.
|
||||
Thread.Sleep(2000);
|
||||
// Wait for TTL to expire (1s TTL + generous margin).
|
||||
await Task.Delay(2_500);
|
||||
|
||||
// Force expiry by storing a new message (expiry check runs before store).
|
||||
store.StoreMsg("test", null, [], 0);
|
||||
@@ -373,7 +374,7 @@ public sealed class FileStoreTombstoneTests : IDisposable
|
||||
// After TTL expiry and restart (without stream state file),
|
||||
// a tombstone should allow proper recovery of the stream state.
|
||||
[Fact]
|
||||
public void MessageTTL_WriteTombstoneAllowsRecovery()
|
||||
public async Task MessageTTL_WriteTombstoneAllowsRecovery()
|
||||
{
|
||||
var dir = UniqueDir("ttl-tombstone");
|
||||
var opts = new FileStoreOptions { Directory = dir, MaxAgeMs = 1000 };
|
||||
@@ -388,8 +389,8 @@ public sealed class FileStoreTombstoneTests : IDisposable
|
||||
ss.FirstSeq.ShouldBe(1UL);
|
||||
ss.LastSeq.ShouldBe(2UL);
|
||||
|
||||
// Wait for seq=1 to expire.
|
||||
Thread.Sleep(1500);
|
||||
// Wait for seq=1 to expire (1s TTL + generous margin).
|
||||
await Task.Delay(2_500);
|
||||
|
||||
// Force expiry.
|
||||
store.StoreMsg("test", null, [], 0);
|
||||
@@ -629,7 +630,6 @@ public sealed class FileStoreTombstoneTests : IDisposable
|
||||
cs1.UpdateDelivered(5, 2, 1, ts);
|
||||
|
||||
cs1.Stop();
|
||||
Thread.Sleep(20); // wait for flush
|
||||
|
||||
// Reopen — should recover redelivered.
|
||||
var cs2 = store.ConsumerStore("o22", DateTime.UtcNow, cfg);
|
||||
@@ -641,7 +641,6 @@ public sealed class FileStoreTombstoneTests : IDisposable
|
||||
cs2.UpdateDelivered(7, 3, 1, ts);
|
||||
|
||||
cs2.Stop();
|
||||
Thread.Sleep(20);
|
||||
|
||||
// Reopen again.
|
||||
var cs3 = store.ConsumerStore("o22", DateTime.UtcNow, cfg);
|
||||
@@ -654,7 +653,6 @@ public sealed class FileStoreTombstoneTests : IDisposable
|
||||
cs3.UpdateAcks(6, 2);
|
||||
|
||||
cs3.Stop();
|
||||
Thread.Sleep(20);
|
||||
|
||||
// Reopen and ack 4.
|
||||
var cs4 = store.ConsumerStore("o22", DateTime.UtcNow, cfg);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
using NATS.Server.JetStream.Models;
|
||||
using NATS.Server.JetStream.Storage;
|
||||
using NATS.Server.TestUtilities;
|
||||
|
||||
namespace NATS.Server.JetStream.Tests.JetStream.Storage;
|
||||
|
||||
@@ -491,7 +492,7 @@ public sealed class MemStoreGoParityTests
|
||||
s.StoreMsg("A", null, "OK"u8.ToArray(), 0);
|
||||
if (i == total / 2)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
Thread.Sleep(250);
|
||||
midTime = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
@@ -593,7 +594,7 @@ public sealed class MemStoreGoParityTests
|
||||
|
||||
// Go: TestMemStoreMessageTTL server/memstore_test.go:1202
|
||||
[Fact]
|
||||
public void MessageTTL_ExpiresAfterDelay()
|
||||
public async Task MessageTTL_ExpiresAfterDelay()
|
||||
{
|
||||
var cfg = new StreamConfig
|
||||
{
|
||||
@@ -616,8 +617,13 @@ public sealed class MemStoreGoParityTests
|
||||
ss.LastSeq.ShouldBe(10UL);
|
||||
ss.Msgs.ShouldBe(10UL);
|
||||
|
||||
// Wait for TTL to expire (> 1 sec + check interval of 1 sec)
|
||||
Thread.Sleep(2_500);
|
||||
// Wait for TTL to expire
|
||||
await PollHelper.WaitOrThrowAsync(() =>
|
||||
{
|
||||
var ss2 = new StreamState();
|
||||
s.FastState(ref ss2);
|
||||
return ss2.Msgs == 0;
|
||||
}, "TTL expiry", timeoutMs: 10_000, intervalMs: 100);
|
||||
|
||||
s.FastState(ref ss);
|
||||
ss.FirstSeq.ShouldBe(11UL);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
using NATS.Server.JetStream.Models;
|
||||
using NATS.Server.JetStream.Storage;
|
||||
using NATS.Server.TestUtilities;
|
||||
|
||||
namespace NATS.Server.JetStream.Tests.JetStream.Storage;
|
||||
|
||||
@@ -286,8 +287,7 @@ public sealed class StoreInterfaceTests
|
||||
|
||||
// Go: TestStoreUpdateConfigTTLState server/store_test.go:574
|
||||
[Fact]
|
||||
[SlopwatchSuppress("SW004", "TTL expiry test requires real wall-clock time to elapse; Thread.Sleep waits for message TTL to expire or survive")]
|
||||
public void UpdateConfigTTLState_MessageSurvivesWhenTtlDisabled()
|
||||
public async Task UpdateConfigTTLState_MessageSurvivesWhenTtlDisabled()
|
||||
{
|
||||
var cfg = new StreamConfig
|
||||
{
|
||||
@@ -301,7 +301,7 @@ public sealed class StoreInterfaceTests
|
||||
|
||||
// TTLs disabled — message with ttl=1s should survive even after 2s.
|
||||
var (seq, _) = s.StoreMsg("foo", null, [], 1);
|
||||
Thread.Sleep(2_000);
|
||||
await Task.Delay(2_500);
|
||||
// Should not throw — message should still be present.
|
||||
var loaded = s.LoadMsg(seq, null);
|
||||
loaded.Sequence.ShouldBe(seq);
|
||||
@@ -312,9 +312,11 @@ public sealed class StoreInterfaceTests
|
||||
|
||||
// TTLs enabled — message with ttl=1s should expire.
|
||||
var (seq2, _) = s.StoreMsg("foo", null, [], 1);
|
||||
Thread.Sleep(2_500);
|
||||
// Should throw — message should have expired.
|
||||
Should.Throw<KeyNotFoundException>(() => s.LoadMsg(seq2, null));
|
||||
await PollHelper.WaitOrThrowAsync(() =>
|
||||
{
|
||||
try { s.LoadMsg(seq2, null); return false; }
|
||||
catch (KeyNotFoundException) { return true; }
|
||||
}, "TTL expiry", timeoutMs: 10_000, intervalMs: 100);
|
||||
|
||||
// Now disable TTLs again.
|
||||
cfg.AllowMsgTtl = false;
|
||||
@@ -322,7 +324,7 @@ public sealed class StoreInterfaceTests
|
||||
|
||||
// TTLs disabled — message with ttl=1s should survive.
|
||||
var (seq3, _) = s.StoreMsg("foo", null, [], 1);
|
||||
Thread.Sleep(2_000);
|
||||
await Task.Delay(2_500);
|
||||
// Should not throw — TTL wheel is gone so message stays.
|
||||
var loaded3 = s.LoadMsg(seq3, null);
|
||||
loaded3.Sequence.ShouldBe(seq3);
|
||||
|
||||
Reference in New Issue
Block a user