Commit Graph

509 Commits

Author SHA1 Message Date
Joseph Doherty
a6be5e11ed refactor: extract NATS.Server.Mqtt.Tests project
Move 29 MQTT test files from NATS.Server.Tests into a dedicated
NATS.Server.Mqtt.Tests project. Update namespaces, add
InternalsVisibleTo, and replace Task.Delay calls with
PollHelper.WaitUntilAsync for proper synchronization.
2026-03-12 15:03:12 -04:00
Joseph Doherty
d2c04fcca5 refactor: extract NATS.Server.Transport.Tests project
Move TLS, OCSP, WebSocket, Networking, and IO test files from
NATS.Server.Tests into a dedicated NATS.Server.Transport.Tests
project. Update namespaces, replace private GetFreePort/ReadUntilAsync
with shared TestUtilities helpers, extract TestCertHelper to
TestUtilities, and replace Task.Delay polling loops with
PollHelper.WaitUntilAsync/YieldForAsync for proper synchronization.
2026-03-12 14:57:35 -04:00
Joseph Doherty
5c608f07e3 Move shared fixtures and parity utilities to TestUtilities project
- git mv JetStreamApiFixture, JetStreamClusterFixture, LeafFixture,
  Parity utilities, and TestData from NATS.Server.Tests to
  NATS.Server.TestUtilities
- Update namespaces to NATS.Server.TestUtilities (and .Parity sub-ns)
- Make fixture classes public for cross-project access
- Add PollHelper to replace Task.Delay polling with SemaphoreSlim waits
- Refactor all fixture polling loops to use PollHelper
- Add 'using NATS.Server.TestUtilities;' to ~75 consuming test files
- Rename local fixture duplicates (MetaGroupTestFixture,
  LeafProtocolTestFixture) to avoid shadowing shared fixtures
- Remove TestData entry from NATS.Server.Tests.csproj (moved to
  TestUtilities)
2026-03-12 14:45:21 -04:00
Joseph Doherty
2a75ee534a feat: create NATS.Server.TestUtilities with shared helpers
Add shared test utility library with TestPortAllocator.GetFreePort() and
SocketTestHelper.ReadUntilAsync() to deduplicate helpers across test projects.
This is the foundation for splitting the monolithic test project into
feature-focused test projects.
2026-03-12 14:29:14 -04:00
Joseph Doherty
fb19b50231 docs: add implementation plan for test project split
13 tasks: create TestUtilities, extract 9 subsystem test projects,
rename remainder to Core.Tests, final verification.
2026-03-12 14:26:58 -04:00
Joseph Doherty
6941d9275b docs: add design doc for splitting NATS.Server.Tests into feature-focused projects
Splits the 609-file monolithic test project into 10 subsystem test projects
plus a shared TestUtilities library for developer ergonomics.
2026-03-12 14:23:06 -04:00
Joseph Doherty
c30e67a69d Fix E2E test gaps and add comprehensive E2E + parity test suites
- Fix pull consumer fetch: send original stream subject in HMSG (not inbox)
  so NATS client distinguishes data messages from control messages
- Fix MaxAge expiry: add background timer in StreamManager for periodic pruning
- Fix JetStream wire format: Go-compatible anonymous objects with string enums,
  proper offset-based pagination for stream/consumer list APIs
- Add 42 E2E black-box tests (core messaging, auth, TLS, accounts, JetStream)
- Add ~1000 parity tests across all subsystems (gaps closure)
- Update gap inventory docs to reflect implementation status
2026-03-12 14:09:23 -04:00
Joseph Doherty
79c1ee8776 Add Go-to-.NET gap inventory docs to track porting parity 2026-02-25 15:12:52 -05:00
Joseph Doherty
339c60bac6 docs: mark all remaining gaps as IMPLEMENTED in structuregaps.md
Updated gaps 1.5-1.10, 2.4, 2.7-2.12, 3.1, 3.5, 3.8-3.13, 7.1-7.6,
and 8.3-8.8 with IMPLEMENTED status, implementation file references,
task/phase numbers, and test file names. All 93 sub-gaps across 15
sections are now marked as IMPLEMENTED. Updated test count to 6,920.
2026-02-25 13:35:15 -05:00
Joseph Doherty
6f354baae9 docs: add implementation plan files for gap closure phases
Includes production gaps plan (15 gaps, 4 phases) and remaining gaps
plan task persistence file (93 gaps, 8 phases) — both fully executed.
2026-02-25 13:27:45 -05:00
Joseph Doherty
2cd71dba00 docs: update test_parity.db — 6,920 .NET tests registered (+1,006 new)
Added 1,006 new test entries from the 8-phase remaining gaps
implementation across JetStream, Auth, Routes, LeafNodes, Monitoring,
Events, Config, Gateway, WebSocket, and Internal test directories.
2026-02-25 13:27:40 -05:00
Joseph Doherty
5f50e12829 docs: mark all 93 remaining gaps as IMPLEMENTED in structuregaps.md
Updated all gap sections (3-15) with IMPLEMENTED status markers,
implementation file references, and test file names covering all
8 phases of the remaining gaps plan.
2026-02-25 13:25:37 -05:00
Joseph Doherty
4ba87c4175 feat: add OCSP peer reject and chain validation events (Gap 10.10)
Add OcspChainValidationEvent DTO, OcspStatus enum, and OcspEventBuilder
helper with BuildPeerReject, BuildChainValidation, and ParseStatus methods.
Register OcspChainValidationEvent in EventJsonContext source-gen context.
Add OcspPeerReject and OcspChainValidation subject constants to EventSubjects.
10 new tests in OcspEventTests cover all DTOs, builder methods, status
parsing, and JSON round-trip.
2026-02-25 13:15:44 -05:00
Joseph Doherty
b314e3f510 feat: add S2 compression for system events (Gap 10.9)
Add EventCompressor static class with Snappy/S2 compress/decompress,
threshold-based ShouldCompress, CompressIfBeneficial with stats tracking,
and GetCompressionRatio helpers. Port 10 tests covering round-trip,
threshold logic, stats (TotalCompressed, BytesSaved, ResetStats).
Go reference: server/events.go:2082-2098 compressionType / snappyCompression.
2026-02-25 13:15:24 -05:00
Joseph Doherty
74473d81cf feat: add WebSocket-specific TLS configuration (Gap 15.1) 2026-02-25 13:14:47 -05:00
Joseph Doherty
4b9384dfcf feat: add auth error event publication (Gap 10.5)
Add SendAuthErrorEvent, SendConnectEvent, SendDisconnectEvent to
InternalEventSystem, plus AuthErrorEventCount counter and the three
companion detail record types (AuthErrorDetail, ConnectEventDetail,
DisconnectEventDetail). 10 new tests in AuthErrorEventTests all pass.
2026-02-25 13:12:52 -05:00
Joseph Doherty
10ac904b5c feat: add remote server events for cluster visibility (Gap 10.8)
Add RemoteServerShutdownEvent, RemoteServerUpdateEvent, LeafNodeConnectEvent,
and LeafNodeDisconnectEvent types plus matching EventSubjects constants, with
10 unit tests covering type identity, field assignment, format placeholders,
and JSON roundtrip serialization.
2026-02-25 13:11:59 -05:00
Joseph Doherty
a6e7778c6c feat: complete system event payload fields (Gap 10.6)
Add EventBuilder static class to EventTypes.cs with helpers for constructing
fully-populated ConnectEventMsg, DisconnectEventMsg, AccountNumConns, and
ServerStatsMsg. Also add RemoteServerShutdownEvent, RemoteServerUpdateEvent,
LeafNodeConnectEvent, and LeafNodeDisconnectEvent advisory types.

Add FullEventPayloadTests.cs (10 tests) covering all builders, GenerateEventId
uniqueness, GetTimestamp ISO 8601 format, DataStats zero defaults, and
ConnectEventMsg JSON roundtrip.
2026-02-25 13:11:58 -05:00
Joseph Doherty
619acc3c08 feat: add sort options to /connz (Gap 10.3)
Add ConnzSortOption enum (ConnectionId, Start, BytesTo, BytesFrom,
MsgsTo, MsgsFrom, Subscriptions, Pending, Uptime, Idle, LastActivity)
and ConnzSorter static class with Parse(string?) and Sort(IEnumerable<ConnInfo>,
ConnzSortOption, bool) methods.

Add SortBy and SortDescending properties to ConnzFilterOptions and wire
them through ConnzFilterOptions.Parse (?sort= and ?desc= query params).

Add 10 unit tests in ConnzSortTests covering Parse defaults, known values,
unknown string fallback, and sort ordering for key fields.

Go reference: server/monitor_sort_opts.go, server/monitor.go Connz().
2026-02-25 13:09:11 -05:00
Joseph Doherty
9ece600ebc feat: add closed connection ring buffer for /connz?state=closed (Gap 10.1)
Replace ConcurrentQueue<ClosedClient> with ClosedConnectionRingBuffer — a
fixed-size ring buffer that overwrites oldest entries when full, eliminating
the manual dequeue-to-cap loop. Adds TotalClosed lifetime counter, GetRecent(),
and Clear(). Wires the ring buffer into NatsServer including capacity resize
on config reload. Adds 10 unit tests covering capacity, ordering, wrapping,
TotalClosed tracking, and Clear behavior.
2026-02-25 13:07:16 -05:00
Joseph Doherty
9fb2ae205c feat: add message trace propagation across servers (Gap 10.4)
Add TraceContextPropagator and TraceContext to Internal/MessageTraceContext.cs
for Nats-Trace-Parent header injection and extraction across server hops.
Also add ConnzSortOption/ConnzSorter stubs to fix pre-existing build errors
in Monitoring/Connz.cs. Covered by 10 new tests in TraceContextPropagationTests.cs.
2026-02-25 13:06:58 -05:00
Joseph Doherty
eb801cd4cf feat: add account-scoped filtering to /connz (Gap 10.2)
Add ConnzConnectionInfo, ConnzFilterResult, ConnzFilterOptions, and
ConnzFilter static class to Connz.cs, providing a pure unit-testable
layer for account-scoped filtering and pagination that mirrors the Go
server's /connz ?acc= query-parameter behaviour.  Ten new tests in
ConnzAccountFilterTests.cs cover FilterByAccount (match, no-match,
case-insensitive), ConnzFilterOptions.Parse (acc param, defaults,
offset/limit), and ApplyFilters (account filter, offset, limit,
no-filter pass-through).
2026-02-25 13:04:20 -05:00
Joseph Doherty
68b8a0cee5 feat: add service import shadowing detection (Gap 9.10)
Implements ServiceImportShadowed, GetShadowedServiceImports, HasShadowedImports,
and CheckServiceImportShadowing on Account to detect when local SubList subscriptions
would intercept messages before a service import can receive them. Adds ShadowCheckResult
record and 10 tests covering exact, wildcard, and gt-wildcard shadowing scenarios.
2026-02-25 13:00:48 -05:00
Joseph Doherty
ce452febd7 feat: add reverse response mapping for cross-account request-reply (Gap 9.9) 2026-02-25 12:59:49 -05:00
Joseph Doherty
e4b5ed9a83 feat: add JWT activation claim expiration checking (Gap 9.7)
Add ActivationClaim and ActivationCheckResult types plus five methods on
Account (RegisterActivation, CheckActivationExpiry, IsActivationExpired,
GetExpiredActivations, RemoveExpiredActivations) and an ActiveActivationCount
property, mirroring Go accounts.go checkActivation / activationExpired logic.
Adds 10 targeted tests in Auth/ActivationExpirationTests.cs (all pass).
2026-02-25 12:57:41 -05:00
Joseph Doherty
e2bfca48e4 feat: add account expiration with TTL-based cleanup (Gap 9.5)
Add ExpiresAt, IsExpired, TimeToExpiry, SetExpiration, ClearExpiration,
SetExpirationFromTtl, and GetExpirationInfo to Account. Expiry is stored
as UTC ticks in a long field (long.MinValue sentinel) for lock-free reads
via Interlocked. Add AccountExpirationInfo record. 10 new tests cover all
behaviours.
2026-02-25 12:56:48 -05:00
Joseph Doherty
2bdf0e75ed feat: add stream import cycle detection (Gap 9.3)
Add StreamImportFormsCycle DFS method to Account plus GetStreamImportSources
and HasStreamImportFrom helpers. Add GetStreamImportSourceAccounts to ImportMap.
10 tests cover direct, indirect, self, diamond, and empty import scenarios.
2026-02-25 12:53:04 -05:00
Joseph Doherty
3107615885 feat: add service export latency tracking with p50/p90/p99 (Gap 9.1)
Add ServiceLatencyTracker with sorted-sample histogram, percentile getters (p50/p90/p99), average/min/max, reset, and immutable snapshot. Wire LatencyTracker and RecordServiceLatency onto Account. Cover with 11 xUnit tests.
2026-02-25 12:52:05 -05:00
Joseph Doherty
dcd6b78a89 feat: add leaf node JetStream migration checks (Gap 12.4)
Implements CheckJetStreamMigrate, GetActiveJetStreamDomains,
IsJetStreamDomainInUse, and JetStreamEnabledConnectionCount on
LeafNodeManager. Adds JetStreamMigrationResult/JetStreamMigrationStatus
result types. Ten unit tests cover all validation paths (10/10 pass).
2026-02-25 12:24:30 -05:00
Joseph Doherty
1a9d3f06e6 feat: add leaf cluster registration and topology tracking (Gap 12.6) 2026-02-25 12:24:03 -05:00
Joseph Doherty
80e5cc1be5 feat: add leaf node WebSocket support with stream adapter (Gap 12.5)
Implements WebSocketStreamAdapter — a Stream subclass that wraps
System.Net.WebSockets.WebSocket for use by LeafConnection. Handles
message framing (per-message receive/send), tracks BytesRead/BytesWritten
and MessagesRead/MessagesWritten counters, and exposes IsConnected. Ten
NSubstitute-based unit tests cover all capability flags, delegation, and
telemetry (10/10 pass).
2026-02-25 12:23:53 -05:00
Joseph Doherty
2683e6b7ed feat: add no-pool route fallback for backward compatibility (Gap 13.6)
Add SupportsPooling/IsLegacyRoute properties to RouteConnection and
GetLegacyRoute/GetLegacyRoutes/HasLegacyRoutes to RouteManager. Update
GetRouteForAccount to fall back to legacy routes when no dedicated or
pool-capable route is available, matching Go route.go getRoutesExcludePool.
2026-02-25 12:19:56 -05:00
Joseph Doherty
4f3187ae62 feat: add leaf node permission and account syncing (Gap 12.2)
Add SetPermissions/PermsSynced/AllowedPublishSubjects/AllowedSubscribeSubjects/AccountName
to LeafConnection, and SendPermsAndAccountInfo/InitLeafNodeSmapAndSendSubs/GetPermSyncStatus
plus LeafPermSyncResult to LeafNodeManager. Add OnConnectionRegistered internal callback for
test synchronization. 10 new unit tests in LeafPermissionSyncTests.cs all passing.
2026-02-25 12:11:50 -05:00
Joseph Doherty
629bbd13fa feat: add leaf connection state validation on reconnect (Gap 12.3)
Adds ValidateRemoteLeafNode to LeafNodeManager with self-connect,
duplicate-connection, and JetStream domain conflict checks, plus
IsSelfConnect, HasConnection, and GetConnectionByRemoteId helpers.
Introduces LeafValidationResult and LeafValidationError types.
Adds 10 unit tests in LeafValidationTests covering all error codes.
2026-02-25 12:10:44 -05:00
Joseph Doherty
ef425db187 feat: add leaf node TLS certificate hot-reload (Gap 12.1)
Add UpdateTlsConfig to LeafNodeManager with CurrentCertPath, CurrentKeyPath,
IsTlsEnabled, and TlsReloadCount. Add LeafTlsReloadResult record. Add 10 unit
tests in LeafTlsReloadTests covering change detection, no-op idempotency, path
tracking, counter semantics, and result payload.
2026-02-25 12:08:15 -05:00
Joseph Doherty
b9c83d6b3b feat: add route pool size negotiation (Gap 13.3)
Add NegotiatePoolSize static method and NegotiatedPoolSize property to
RouteConnection, and ConfiguredPoolSize / GetEffectivePoolSize to
RouteManager. Includes 14 tests covering negotiation semantics, backward
compatibility (zero means no pooling), default state, and deterministic
pool index computation.
2026-02-25 12:05:57 -05:00
Joseph Doherty
071717dcbf feat: add cluster split handling (Gap 13.5)
Add RemoveRoute, RemoveAllRoutesExcept, RegisterRoute (internal), and
DetectClusterSplit to RouteManager with ClusterSplitResult record, plus
10 tests covering partition detection and route removal behavior.
2026-02-25 12:03:05 -05:00
Joseph Doherty
3192caeab8 feat: add route hash storage for O(1) lookup (Gap 13.4)
Add ConcurrentDictionary<ulong, RouteConnection> _routesByHash with FNV-1a
64-bit hash key, RegisterRouteByHash/UnregisterRouteByHash/GetRouteByHash/
GetRouteByServerId methods, and HashedRouteCount property to RouteManager.
Includes 10 unit tests covering determinism, distinct hashes, CRUD lifecycle,
overwrite semantics, and no-op unregister.
2026-02-25 12:02:35 -05:00
Joseph Doherty
7f3e2e0e0b feat: add account-specific dedicated routes (Gap 13.2)
Add _accountRoutes ConcurrentDictionary to RouteManager with full
CRUD API: RegisterAccountRoute, UnregisterAccountRoute,
GetDedicatedAccountRoute, HasDedicatedRoute,
GetAccountsWithDedicatedRoutes, and DedicatedRouteCount property.
Update GetRouteForAccount to check dedicated routes before falling
back to pool-based selection. Add 10 unit tests in AccountRouteTests.
2026-02-25 12:01:49 -05:00
Joseph Doherty
5fd23571dc feat: add gateway connection registration with state tracking (Gap 11.7)
Adds GatewayConnectionState enum, GatewayRegistration record with atomic
message counters, and a full registry API on GatewayManager: RegisterGateway,
UpdateState, GetRegistration, GetAllRegistrations, UnregisterGateway,
GetConnectedGatewayCount, IncrementMessagesSent, IncrementMessagesReceived.
Covers 11 new tests in GatewayRegistrationTests.cs (all passing).
2026-02-25 11:54:52 -05:00
Joseph Doherty
684254ad86 feat: add gateway command protocol with Go-compatible wire format (Gap 11.6)
Add GatewayCommands static class with wire-format byte sequences (GINFO, GS+, GS-,
GMODE, GMSG, GPING, GPONG) and FormatSub/FormatUnsub/FormatMode/ParseCommandType
helpers matching Go's gateway.go protocol constants. Add GatewayCommandType enum.
10 tests covering all wire formats and command parsing.
2026-02-25 11:54:30 -05:00
Joseph Doherty
dc8d28c222 feat: add reply subject mapping cache with TTL (Gap 11.5)
Add ReplyMapCache to ReplyMapper.cs — an LRU cache with TTL expiration
for gateway reply subject mappings, avoiding repeated string parsing on
the hot path. Includes 10 unit tests covering LRU eviction, TTL expiry,
hit/miss counters, PurgeExpired, and Count.
2026-02-25 11:51:55 -05:00
Joseph Doherty
455a91579a feat: add gateway reconnection with exponential backoff (Gap 11.2)
Adds GatewayReconnectPolicy with exponential backoff and jitter, and
reconnect attempt tracking (GetReconnectAttempts, ResetReconnectAttempts,
ReconnectGatewayAsync) to GatewayManager. 10 new tests cover delay
calculation, cap behaviour, jitter, and per-gateway counter isolation.
2026-02-25 11:51:40 -05:00
Joseph Doherty
d598276807 feat: add account-specific gateway routes (Gap 11.3)
Adds per-account subscription tracking to GatewayConnection via
AddAccountSubscription/RemoveAccountSubscription/GetAccountSubscriptions/
AccountSubscriptionCount, with corresponding SendAccountSubscriptions and
GetAccountSubscriptions helpers on GatewayManager. Covered by 10 new unit tests.
2026-02-25 11:51:09 -05:00
Joseph Doherty
4c53159de8 feat: add runtime logging level changes (Gap 14.5)
Adds LoggingChangeResult and ApplyLoggingChanges to ConfigReloader, deriving
an effective log level from Debug/Trace flags (Trace > Debug > Information) and
reporting flag-level and level-string changes for hot-reload notification.
2026-02-25 11:48:29 -05:00
Joseph Doherty
ff07137ea6 feat: add JetStream config change reload (Gap 14.6)
Add ApplyJetStreamConfigChanges to ConfigReloader for detecting MaxMemoryStore,
MaxFileStore, and Domain changes during hot reload. Add Domain property to
JetStreamOptions. Port 10 unit tests covering all change permutations.
2026-02-25 11:48:22 -05:00
Joseph Doherty
5116aed491 feat: add TLS certificate hot-reload for new connections (Gap 14.3)
Add ReloadTlsCertificates(oldOpts, newOpts) returning TlsReloadResult for
path-based cert comparison and validation during config hot-reload. Add 10
targeted tests covering no-change, path detection, missing file, null transitions,
and success cases.
2026-02-25 11:48:11 -05:00
Joseph Doherty
074ff6b287 feat: add cluster config hot reload (Gap 14.4)
Adds ClusterConfigChangeResult and ApplyClusterConfigChanges to ConfigReloader,
comparing route/gateway/leaf URL sets between old and new NatsOptions and reporting
added/removed routes for connection reconciliation on hot reload.
2026-02-25 11:47:02 -05:00
Joseph Doherty
42e072ad71 feat: add auth change propagation to existing connections (Gap 14.2)
Add PropagateAuthChanges to ConfigReloader that compares Users, Accounts,
and Authorization token between old and new NatsOptions, returning an
AuthChangeResult describing which auth fields changed for connection re-evaluation.
2026-02-25 11:46:28 -05:00
Joseph Doherty
5fea08dda0 feat: complete MQTT session flapper detection (Gap 6.6)
Add FlapperState class and per-client exponential backoff tracking to
MqttSessionStore. New TrackConnectDisconnect(string) overload returns
FlapperState with backoff level and expiry; IsFlapper, GetBackoffMs,
ClearFlapperState, and CheckAndClearStableClients give callers full
visibility and cleanup control. Legacy two-arg overload preserved for
backward compatibility. Ten unit tests cover counting, threshold,
exponential growth, 60s cap, window reset, and stable-client sweep.
2026-02-25 11:42:24 -05:00