Skip to content

test: deflake TraxAuditWriterTests by polling sink state#43

Merged
Theauxm merged 4 commits into
mainfrom
test/deflake-audit-writer-tests
May 6, 2026
Merged

test: deflake TraxAuditWriterTests by polling sink state#43
Theauxm merged 4 commits into
mainfrom
test/deflake-audit-writer-tests

Conversation

@Theauxm
Copy link
Copy Markdown
Member

@Theauxm Theauxm commented May 6, 2026

Summary

Replaces fixed Task.Delay(300/500/800) waits across four tests with a WaitUntilAsync helper that polls the sink's Batches or Attempts counter until the expected condition holds. Each test finishes as soon as the flush loop or retry path lands the expected effect.

Affected tests:

  • Drains_BatchFull_FlushesImmediately
  • Drains_PartialBatch_FlushesOnInterval
  • SinkThrowsBeyondMaxRetries_DropsBatch
  • SinkThrows_Retries_ThenSucceeds

The 10-second timeout is a safety ceiling, not a sleep. The intentional Task.Delays in Stop_DuringRetryBackoff_PropagatesCancellation and Drains_QuietChannel_Stops_WithoutFlushing are left untouched: those verify behavior during a known-duration sleep, not after one.

Local run for these 6 tests drops from ~2.4s to ~540ms.

Test plan

  • dotnet build — zero warnings
  • dotnet csharpier check . — clean
  • dotnet test --filter TraxAuditWriterTests — 6/6 passing in 540ms

Theauxm added 4 commits May 5, 2026 19:02
Replaces fixed Task.Delay(300/500/800) waits across four tests with
a WaitUntilAsync helper that polls the sink's batches or attempts
counter until the expected condition holds. The 10-second timeout
is a safety ceiling, not a sleep — the tests finish as soon as the
flush loop or retry path lands the expected effect.

Affects:
- Drains_BatchFull_FlushesImmediately
- Drains_PartialBatch_FlushesOnInterval
- SinkThrowsBeyondMaxRetries_DropsBatch
- SinkThrows_Retries_ThenSucceeds

The intentional Task.Delays in Stop_DuringRetryBackoff_PropagatesCancellation
and Drains_QuietChannel_Stops_WithoutFlushing are left untouched; those
verify behavior during a known-duration sleep, not after one.
The helper called WebSocket.ReceiveAsync once and parsed whatever bytes
came back. That fails non-deterministically when:

- A text message arrives in multiple frames (EndOfMessage=false on the
  first read), so the partial buffer fails JSON parsing.
- The host returns a zero-length frame before the actual payload, so
  the empty buffer triggers "input does not contain any JSON tokens".
- The host closes the socket while the test is waiting, in which case
  the test surfaced a confusing JsonReaderException instead of a useful
  diagnostic.

Replaces both ReceiveAsync helpers (in SubscriptionE2ETests and
SubscriptionPrincipalPropagationE2ETests) and the local ReceiveNextAsync
loop with a version that:
- Accumulates fragmented frames into a MemoryStream until EndOfMessage
- Throws a clear InvalidOperationException with CloseStatus details on
  unexpected close frames
- Skips zero-length frames during accumulation rather than failing on
  empty input

Bumps the receive timeout in SubscriptionE2ETests from 5 to 10 seconds
to match the sibling file and provide a single uniform CI ceiling.

Surfaced by a CI run of the audit-writer deflake PR where
RepeatedEvents_SamePrincipalEveryTime hit the empty-buffer path.
Same single-shot ReceiveAsync pattern as the previous commit, lower
flake probability because the test catches WebSocketException, but a
JsonReaderException on a partial buffer escapes the catch and fails
the rejection check for the wrong reason. Mirrors the accumulate-
until-EndOfMessage handling.
@Theauxm Theauxm merged commit 740a5e4 into main May 6, 2026
1 check passed
@Theauxm Theauxm deleted the test/deflake-audit-writer-tests branch May 6, 2026 01:19
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@traxsharp
Copy link
Copy Markdown

traxsharp Bot commented May 8, 2026

This PR is included in version 1.25.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant