Skip to content

fix(tests): make five platform-, order- and size-dependent tests dete… - #29

Merged
dundich merged 1 commit into
mainfrom
fix/ci-flaky-tests
Oct 29, 2026
Merged

dundich merged 1 commit into
mainfrom
fix/ci-flaky-tests

Conversation

@dundich

@dundich dundich commented Oct 29, 2026

Copy link
Copy Markdown
Owner

…rministic

CI was red on both legs, and every failure was a test defect rather than a product regression.

Sa.Outbox.PostgreSqlTests (ubuntu):

  • SelectTenant_ReturnsEveryTenantExactlyOnce relied on the sibling test having seeded all four tenants in the shared fixture table. xUnit guarantees no order, and on the runner this test ran first, so DISTINCT saw only the two tenants it had published itself (expected 4, actual 2). It now seeds every configured tenant itself, two messages each, keeping the dedup meaningful.

Sa.Utils.WorkQueue.Tests (ubuntu):

  • ShutdownAsync_StopsProcessing expected exactly five Cancelled callbacks, but the default pool is ConcurrencyLimit ?? ProcessorCount readers with a buffer of the same size. On a 4-core runner only four items were in flight, the fifth was drained as Faulted ("dropped") instead of Cancelled, and the count went 5 != 4. The pool is now sized explicitly and the test waits for all five items to actually start instead of sleeping 50 ms.

Sa.Media.FFmpegTests (windows):

  • OwnTimeout_FiresAtTheDeadlineNotAtProcessDeath hardcoded "sleep" in the timeout message, while LongRunningProcess starts ping on Windows. The expectation is now platform-aware.
  • ConvertToOgg_ShouldBeWork used RequireEncoderAvailable("libvorbis"), which fails, although the test documents that a stale win-x64 payload should skip. Switched to EnsureEncoderAvailable, and CodecProbe now trims whitespace before trimming the punctuation (Windows lines arrive with '\r'). The skip reason carries the detected executable path, its version and the external encoders that were found, so a missing encoder can be told apart from the probe picking up a foreign ffmpeg.

SaTests:

  • Levenshtein_Distance_StringsLongerThanStack_DoNotOverflow used two 60 000-char strings, and the DP is O(n*m): 3.6e9 cell updates, measured 21 s in Release and well over a minute in Debug, where the test's own 60-second thread Join turned a slow run into "Test thread did not finish". The size only has to overflow the stack of a naive stackalloc of the three int rows: 6 000 chars give 3 * 6 001 * 4 = 72 KB on a dedicated 64 KB stack, so the regression is still detected while the compute drops to 0.38 s Release / 1.0 s Debug. RunOnSmallStackThread takes the stack size (default: the 256 KB ASP.NET-like one) and quadratic work gets SmallStackBytesForQuadraticWork.

@dundich
dundich force-pushed the fix/ci-flaky-tests branch from 767ec12 to d8ea2f1 Compare October 29, 2026 12:10
…s deterministic

CI was red on both legs, and every failure was a test defect rather than a
product regression.

Sa.Outbox.PostgreSqlTests (ubuntu):
- SelectTenant_ReturnsEveryTenantExactlyOnce relied on the sibling test having
  seeded all four tenants in the shared fixture table. xUnit guarantees no
  order, and on the runner this test ran first, so DISTINCT saw only the two
  tenants it had published itself (expected 4, actual 2). It now seeds every
  configured tenant itself, two messages each, keeping the dedup meaningful.

Sa.Utils.WorkQueue.Tests (ubuntu):
- ShutdownAsync_StopsProcessing expected exactly five Cancelled callbacks, but
  the default pool is ConcurrencyLimit ?? ProcessorCount readers with a buffer
  of the same size. On a 4-core runner only four items were in flight, the
  fifth was drained as Faulted ("dropped") instead of Cancelled, and the count
  went 5 != 4. The pool is now sized explicitly and the test waits for all five
  items to actually start instead of sleeping 50 ms.
- The WorkQueueSyncReaderTests snapshot helper enumerated _readers without the
  queue's own _readersSync, so it raced with readers being removed from their
  own threads: "Collection was modified; enumeration operation may not execute"
  out of ReArm_WhileCancellingReaders_... The fault was in the snapshot, not in
  the queue. The helper now takes the very same System.Threading.Lock
  (Enter/Exit through reflection, because EnterScope returns a ref struct;
  Monitor would take the object's monitor, which a Lock does not use).

Sa.Media.FFmpegTests (windows):
- OwnTimeout_FiresAtTheDeadlineNotAtProcessDeath hardcoded "sleep" in the
  timeout message, while LongRunningProcess starts ping on Windows. The
  expectation is now platform-aware.
- ConvertToOgg_ShouldBeWork used RequireEncoderAvailable("libvorbis"), which
  fails, although the test documents that a stale win-x64 payload should skip.
  Switched to EnsureEncoderAvailable, and CodecProbe now trims whitespace
  before trimming the punctuation (Windows lines arrive with '\r'). The skip
  reason carries the detected executable path, its version and the external
  encoders that were found, so a missing encoder can be told apart from the
  probe picking up a foreign ffmpeg.

SaTests:
- Levenshtein_Distance_StringsLongerThanStack_DoNotOverflow used two 60 000-char
  strings, and the DP is O(n*m): 3.6e9 cell updates, measured 21 s in Release
  and well over a minute in Debug, where the test's own 60-second thread Join
  turned a slow run into "Test thread did not finish". The size only has to
  overflow the stack of a naive stackalloc of the three int rows: 6 000 chars
  give 3 * 6 001 * 4 = 72 KB on a dedicated 64 KB stack, so the regression is
  still detected while the compute drops to 0.38 s Release / 1.0 s Debug.
  RunOnSmallStackThread takes the stack size (default: the 256 KB ASP.NET-like
  one) and quadratic work gets SmallStackBytesForQuadraticWork.
@dundich
dundich force-pushed the fix/ci-flaky-tests branch from d8ea2f1 to a36f7c0 Compare October 29, 2026 12:10
@dundich
dundich merged commit d525305 into main Oct 29, 2026
2 checks passed
@dundich
dundich deleted the fix/ci-flaky-tests branch October 29, 2026 12:50
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