Skip to content

The Drift Log · Model independence and repeatable builds

Isolating Network Ordering in Asynchronous Test Suites

6 September 2026 · 3 min read · 710 words · established

Two identical crystal prisms casting exactly the same refraction

Eliminate asynchronous test flakiness by swapping kernel loopback sockets for caller-stepped virtual transports and deterministic queues.

An integration test passes ten times locally, fails once in continuous integration, passes on retry, and gets merged anyway. Three weeks later, a patch to an unrelated package fails on the same assertion because the CI worker had slightly higher CPU contention during an asynchronous socket flush.

Flaky tests are rarely caused by broken logic. They are caused by non-deterministic runtime environments leaking into the test boundary. When an asynchronous test suite relies on real network sockets, kernel poll loops, or uncoordinated background tasks, it stops verifying functional correctness and begins measuring scheduling jitter.

If you want truly deterministic software, you have to treat execution order the same way you treat clocks and seeded randomness: as an explicit, caller-controlled input.

The Mirage of Real Network Fixtures

Most asynchronous test setups attempt to isolate network operations by spinning up ephemeral local servers on random high-numbered ports. The theory is that a real loopback socket exercises the real code path without external dependencies.

In practice, this swaps external latency variance for kernel scheduling variance.

When your code fires two concurrent HTTP requests or writes to two multiplexed streams, loopback transit is fast enough that the arrival order depends entirely on OS thread slicing. If Handler A finishes before Handler B 98% of the time, your assertions pass. The moment a heavy build runs on an adjacent core, Handler B wins the race, an out-of-order state change occurs, and the build fails.

Wrapping these assertions in arbitrary polling loops (waitFor, eventually, or sleep) does not solve the race. It widens the timing window until the test passes often enough to ignore, masking actual concurrency regressions and turning a five-second test suite into a four-minute build bottleneck.

Virtual Schedulers and Sequence Queues

Eliminating network race conditions requires removing the real event loop from the test boundary entirely. You must replace non-deterministic I/O with an explicit sequence scheduler.

// Replace spontaneous async execution with a deterministic step driver
let mut transport = MockTransport::new();
transport.enqueue_response(200, b"{\"status\": \"queued\"}");
transport.enqueue_response(409, b"{\"error\": \"conflict\"}");

let mut client = WorkerClient::new(transport.handle());
let mut future_a = client.submit_job(job_a);
let mut future_b = client.submit_job(job_b);

// Explicitly advance the virtual network queue in exact sequence
transport.step(); // Resolves future_a
transport.step(); // Resolves future_b

assert_eq!(future_a.now_or_never().unwrap().unwrap().status, "queued");
assert_eq!(future_b.now_or_never().unwrap().unwrap_err().code, 409);

In this model, time and transit do not advance automatically in the background. A request yields a pending future that does not poll an operating system socket. It sits in an in-memory queue until the test explicitly calls step().

This delivers three structural properties:

  1. Total reproducibility: If a sequence fails, running the same sequence with the same seed will fail at the exact same step, every time, across every machine.
  2. Zero timing margins: Tests execute instantly because they do not wait for timeouts, timers, or thread context switches.
  3. Interleaving control: You can deliberately invert the step order (step_b() before step_a()) to test race resilience directly, turning accidental race conditions into intentional regression checks.

As we discuss in Why Model Independence Is an Engineering Posture, eliminating runtime variance is the only way to build systems that can be rigorously certified.

How SHPBL Enforces Execution Determinism

At SHPBL, we treat determinism as an absolute property. No AI model runs inside our software, and no component relies on dynamic runtime model output or unpredictable background loops.

Our verification happens inside a strict certification harness. The harness runs artifacts through an automated gauntlet and returns a strict, non-negotiable verdict: CERTIFIED, PROVISIONAL (reproducible execution, but functional correctness not yet asserted), INCONCLUSIVE (the harness could not exercise the contract), or FAILED.

Every artifact is tested against sealed inputs, fixed seeds, and isolated execution steps. That rigor is why we can publish reproducible builds backed by exact archive checksums: what passes the harness produces the identical result in production.

What to Do on Monday

Do not rewrite your entire test suite this week. Target the single most frequent intermittent failure in your CI log.

  1. Find the socket or timer: Identify where that test interacts with an actual event loop, loopback socket, or wall-clock timer.
  2. Inject a transport interface: Extract the network boundary into a trait or interface that allows passing messages synchronously via an in-memory buffer.
  3. Control the step loop: Rewrite the test to manually advance the transport buffer step-by-step. Remove every sleep, retry, and polling assertion in that file.

Once execution order is driven by your test code rather than the kernel scheduler, the test will either pass reliably on every run or fail with an actionable, reproducible trace.

This post supports the longer argument in Why Model Independence Is an Engineering Posture.

Keep reading

Next in the log

The Strategic Master Library · written and reviewed under the house's own epistemic rules: nothing claimed that we cannot show.