Gate positive-path test connections with ConnectRetryAsync#1198
Conversation
Many integration tests construct a NatsConnection and exercise it without first gating on a successful connect. The default ConnectTimeout is 2s and covers the wait for the server INFO frame; when CI runs multiple TFMs of a project in parallel, that 2s wait loses under load and the connect throws a TimeoutException before the test's own logic runs. The failure then points at an unrelated test rather than the connect, and the assertions never ran. Gate positive-path connections with the existing ConnectRetryAsync helper (retries ConnectAsync for up to 60s), and convert plain ConnectAsync setup gates to it. Negative-path tests (expected connect failures/timeouts, reconnect/cancel/TLS/auth behaviour) are left as-is.
|
Claude finished @mtmk's task in 3m 56s —— View job PR Review
Verdict: LGTM with one minor observation. This PR is a well-scoped, mechanical change that correctly gates 48 test setups on a stable connection before exercising the feature under test. All changes are in test files only — no production code is touched.
|
Two timing flakes distinct from the connect-timeout class: Request_reply_many_* sent the request before the responder's SUB was registered server-side, so under load the request could race ahead and get zero replies. Fence the responder with a PING/PONG round-trip before requesting, matching the existing pattern in this file. SlowConsumerDetected_fires_again_after_recovery waited for an absolute slowConsumerCount >= 2, but episode 1 alone can reach 2, so the episode-2 wait could pass without a new event and the >-than assertion then failed. Wait for a count strictly greater than the episode-1 snapshot instead.
Integration tests that construct a NatsConnection and use it without first gating on a successful connect can fail with a TimeoutException from the 2s connect/INFO-wait when CI runs TFMs in parallel under load. The failure surfaces as an unrelated test before any assertion runs. Gate positive-path connections with the existing ConnectRetryAsync helper (retries ConnectAsync for up to 60s) and convert plain ConnectAsync setup gates to it. Negative-path tests (expected connect failures/timeouts, reconnect/cancel/TLS/auth behaviour) are left as-is.
Also fixes two unrelated test flakes surfaced by CI: a request-reply race where the request could outrun the responder's subscription, and a slow-consumer test whose episode-2 wait used an absolute event-count threshold instead of a relative one.