Software QA / Editorial solution guide

Diagnose test data leaking between runs

Trace unexpected records to the fixture lifecycle and restore isolation using synthetic data.

About 3 min readContent reviewed

Read-only knowledge base · No public comments

Recognize the symptoms

A case expects one enrollment but sees two, or a newly created account is already present. The failure may appear only after an earlier run, after an interrupted setup, or when workers execute together. Preserve the actual assertion and synthetic identifiers before cleaning anything.

Understand the likely causes

  • A shared fixture can outlive its intended scope; cleanup can be skipped when setup fails; two workers can choose the same key; or an assertion can count unrelated records. These are hypotheses until a controlled comparison identifies the relevant state.

1. Preserve and scope the evidence

Record the revision, selected cases, worker count, fixture identifiers, timestamps and the actual expected and observed counts. Capture only synthetic identifiers and redact credentials or personal data. Note whether the store was fresh, restored from a snapshot or reused. A passing retry after cleanup does not explain which case created the extra record. Keep the initial failure and compare it with a run using the same revision in a separate isolated store. Do not delete shared data merely to make the test pass.

2. Compare isolated and ordered runs

Create a unique namespace for one synthetic test run, then execute the failing case alone. Run the suspected predecessor followed by the case in a second fresh namespace; compare the records owned by each case and their creation and cleanup events. If the failure appears only in the ordered pair, inspect the predecessor’s lifecycle. If it appears only with parallel workers, compare generated keys and transaction boundaries. A different result is a lead, not proof of the root cause: check that the test selection and initial state were otherwise equivalent.

3. Repair fixture ownership and cleanup

Make each case create the records it needs and scope reads to those records. Give each worker a distinct namespace and register cleanup as soon as a resource is created, so a later setup failure does not skip it. Use a fresh database or transaction where the application architecture supports it; a transaction cannot isolate a separate process that uses a different connection automatically. Avoid global deletion in a shared environment. Test cleanup after an intentionally interrupted synthetic setup as well as after success.

4. Verify the repaired lifecycle

Repeat the original case alone, the triggering pair in both orders, and a bounded parallel run against fresh isolated stores. Check the specific expected records before and after cleanup, not merely the test exit status. Simulate setup failure in the lab and confirm that already-created resources are removed without touching another run’s namespace. Record the revision and runs examined. These checks support the repaired lifecycle under the exercised conditions; they do not establish that every external service or failure mode is isolated.

Verify the fix

The original assertion passes with exactly the records owned by its case; a failed setup leaves no owned records, while a neighboring namespace remains intact. Keep the evidence from the original failure and the repaired runs.

Keep it from recurring

  • Document fixture ownership, lifetimes and cleanup behavior in the test harness. Include an isolated failure-path check and periodically examine tests that depend on shared state or suite order.

Official references