Commit Graph

373 Commits

Author SHA1 Message Date
Joseph Doherty
e4d275c929 test: add E2E MQTT bridge tests (pub/sub, different-topic isolation, QoS 1) 2026-03-12 19:54:30 -04:00
Joseph Doherty
c9b55093a4 test: add E2E advanced tests (config, max connections, system events, account imports) 2026-03-12 19:54:05 -04:00
Joseph Doherty
139b984992 test: add E2E WebSocket transport tests (connect, pub/sub round-trip) 2026-03-12 19:52:57 -04:00
Joseph Doherty
571c595d0a test: add E2E cluster tests and fix leaf/gateway using warnings 2026-03-12 19:50:05 -04:00
Joseph Doherty
aeb60d3c43 test: add E2E leaf node tests (hub-to-leaf, leaf-to-hub, subject propagation)
Fix LeafNodeManager.StartAsync to launch solicited connections for RemoteLeaves
(config-file-parsed remotes) in addition to the programmatic Remotes list, and
update ParseEndpoint to handle nats-leaf:// scheme URLs. Add LeafNodeFixture
that polls /leafz for connection readiness and three E2E tests covering
hub→leaf delivery, leaf→hub delivery, and subject-scoped propagation.
2026-03-12 19:47:40 -04:00
Joseph Doherty
338f44b07b test: add E2E gateway tests (cross-gateway messaging, interest-only)
- GatewayFixture: polls /gatewayz monitoring endpoint until both servers
  report num_gateways >= 1, replacing Task.Delay with proper synchronization
- GatewayTests: two tests covering cross-gateway delivery and interest-only
  no-delivery behaviour, using double PingAsync() instead of Task.Delay
- LeafNodeTests: replace Task.Delay(500) with sub.PingAsync()+pub.PingAsync()
  to properly fence subscription propagation without timing dependencies
- Fix GatewayManager.StartAsync to read remotes from RemoteGateways (config-
  parsed) in addition to the legacy Remotes list, enabling config-file-driven
  outbound gateway connections
2026-03-12 19:45:54 -04:00
Joseph Doherty
5d9d1bebd5 test: add E2E JetStream push consumers, ACK policies, retention modes, ordered, mirror, source
Adds 8 new E2E tests to JetStreamTests.cs (tests 11-18) covering push
consumer config, AckNone/AckAll policies, Interest/WorkQueue retention,
ordered consumers, mirror streams, and source streams.

Fixes three server gaps exposed by the new tests: mirror JSON parsing
(deliver_subject and mirror object fields were silently ignored in stream
and consumer API handlers), and deliver_subject omitted from consumer
info wire format. Also fixes ShutdownDrainTests to use TaskCompletionSource
on ConnectionDisconnected instead of a Task.Delay poll loop.
2026-03-12 19:36:29 -04:00
Joseph Doherty
76f8ccec2e test: add E2E header pub/sub tests (HPUB/HMSG) 2026-03-12 19:12:24 -04:00
Joseph Doherty
e094846665 fix: remove unnecessary using directives in monitoring tests 2026-03-12 19:11:27 -04:00
Joseph Doherty
8ad2172e3c test: add E2E monitoring endpoint tests (varz, connz, healthz)
Replace Task.Delay polling with PeriodicTimer in NatsServerProcess readiness
checks and extend StartAsync to also TCP-poll the monitor port when enabled,
so MonitorServerFixture is guaranteed ready before tests run.
2026-03-12 19:10:33 -04:00
Joseph Doherty
4853409a40 chore: add MQTTnet NuGet package for E2E MQTT tests 2026-03-12 19:07:06 -04:00
Joseph Doherty
7fbffffd05 refactor: rename remaining tests to NATS.Server.Core.Tests
- Rename tests/NATS.Server.Tests -> tests/NATS.Server.Core.Tests
- Update solution file, InternalsVisibleTo, and csproj references
- Remove JETSTREAM_INTEGRATION_MATRIX and NATS.NKeys from csproj (moved to JetStream.Tests and Auth.Tests)
- Update all namespaces from NATS.Server.Tests.* to NATS.Server.Core.Tests.*
- Replace private GetFreePort/ReadUntilAsync helpers with TestUtilities calls
- Fix stale namespace in Transport.Tests/NetworkingGoParityTests.cs
2026-03-12 16:14:02 -04:00
Joseph Doherty
78b4bc2486 refactor: extract NATS.Server.JetStream.Tests project
Move 225 JetStream-related test files from NATS.Server.Tests into a
dedicated NATS.Server.JetStream.Tests project. This includes root-level
JetStream*.cs files, storage test files (FileStore, MemStore,
StreamStoreContract), and the full JetStream/ subfolder tree (Api,
Cluster, Consumers, MirrorSource, Snapshots, Storage, Streams).

Updated all namespaces, added InternalsVisibleTo, registered in the
solution file, and added the JETSTREAM_INTEGRATION_MATRIX define.
2026-03-12 15:58:10 -04:00
Joseph Doherty
36b9dfa654 refactor: extract NATS.Server.Auth.Tests project
Move 50 auth/accounts/permissions/JWT/NKey test files from
NATS.Server.Tests into a dedicated NATS.Server.Auth.Tests project.
Update namespaces, replace private GetFreePort/ReadUntilAsync helpers
with TestUtilities calls, replace Task.Delay with TaskCompletionSource
in test doubles, and add InternalsVisibleTo.

690 tests pass.
2026-03-12 15:54:07 -04:00
Joseph Doherty
0c086522a4 refactor: extract NATS.Server.Monitoring.Tests project
Move 39 monitoring, events, and system endpoint test files from
NATS.Server.Tests into a dedicated NATS.Server.Monitoring.Tests project.
Update namespaces, replace private GetFreePort/ReadUntilAsync with
TestUtilities shared helpers, add InternalsVisibleTo, and register
in the solution file. All 439 tests pass.
2026-03-12 15:44:12 -04:00
Joseph Doherty
edf9ed770e refactor: extract NATS.Server.Raft.Tests project
Move 43 Raft consensus test files (8 root-level + 35 in Raft/ subfolder)
from NATS.Server.Tests into a dedicated NATS.Server.Raft.Tests project.
Update namespaces, add InternalsVisibleTo, and fix timing/exception
handling issues in moved test files.
2026-03-12 15:36:02 -04:00
Joseph Doherty
615752cdc2 refactor: extract NATS.Server.Clustering.Tests project
Move 29 clustering/routing test files from NATS.Server.Tests to a
dedicated NATS.Server.Clustering.Tests project. Update namespaces,
replace private GetFreePort/ReadUntilAsync helpers with TestUtilities
calls, and extract TestServerFactory/ClusterTestServer to TestUtilities
to fix cross-project reference from JetStreamStartupTests.
2026-03-12 15:31:58 -04:00
Joseph Doherty
3f7d896a34 refactor: extract NATS.Server.LeafNodes.Tests project
Move 28 leaf node test files from NATS.Server.Tests into a dedicated
NATS.Server.LeafNodes.Tests project. Update namespaces, add
InternalsVisibleTo, register in solution file. Replace all Task.Delay
polling loops with PollHelper.WaitUntilAsync/YieldForAsync from
TestUtilities. Replace private ReadUntilAsync in LeafProtocolTests
with SocketTestHelper.ReadUntilAsync.

All 281 tests pass.
2026-03-12 15:23:33 -04:00
Joseph Doherty
9972b74bc3 refactor: extract NATS.Server.Gateways.Tests project
Move 25 gateway-related test files from NATS.Server.Tests into a
dedicated NATS.Server.Gateways.Tests project. Update namespaces,
replace private ReadUntilAsync with SocketTestHelper from TestUtilities,
inline TestServerFactory usage, add InternalsVisibleTo, and register
the project in the solution file. All 261 tests pass.
2026-03-12 15:10:50 -04:00
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
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
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