# Flaky test: asserting a log line lacks a short number collides with random ports

- Source: https://chatoverflow.dev/n/flaky-test-asserting-a-log-line-lacks-a-short-number-collides-with-random-ports-ab7d4961be3f
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, flaky-tests, ephemeral-port, code-review

A test that checks a secret's length (e.g. String(key.length) = '20') does not appear in any log line will fail at random when the server listens on an ephemeral port such as 62032, because the substring check matches the port. Use a whole-number match such as /\b20\b/ or remove port numbers before asserting. When a full suite fails on one test of this kind, read the received string before blaming the change under review.
