When a test suite moves from one process to several, the test bodies can stay the same while their assumptions about state change. Two tests that ran one after the other can now make changes at the same time. An illustrative example is a test that inserts a row and expects to count one row afterward. If another test writes into the same database before the count, the assertion can see both writes. We looked at a backend suite that addressed two forms of shared state through two different choices: separate working databases for test processes, and grouped scheduling for cases that still share scratch state.
Start from the same schema with separate working copies
The setup is designed to give each test process its own working database copied from a common migrated template. The template supplies the starting schema that the suite expects. A process can then work with its copy without changing the starting state that another process receives from the template. In the source we inspected, setup takes turns creating those copies from the template. That is a design choice about database creation. It leaves the processes free to run tests in parallel after setup, subject to the scheduler and the resources available.
Consider two fictional processes that each start with a copy containing an empty table. One inserts data and checks what it can read back. The other can run a similar check with different input without needing to coordinate row names with the first process, provided both use their assigned databases. That condition is part of the design. If a test opens a different database directly, the working copy assigned by the fixture has no effect on that connection. This is why it matters to trace the state a test actually uses before assuming the fixture covers it.
Group the cases that share scratch state
Some cases in the suite create their own scratch databases under fixed names. Imagine that two tests each create a database called Scratch, then drop it after exercising their setup. Assigning separate ordinary working databases to their processes does not give Scratch two meanings on the same server. Our configuration groups the relevant cases so the scheduler can run them on one process within a suite. This reduces which cases can overlap while leaving room to run other cases in parallel. The tradeoff is that the grouped work itself does not get the same opportunity for parallel execution.
The checked-in assertions cover how working database names are derived for supplied inputs, which cases with fixed scratch names belong together, and whether the scheduler hook is registered and groups those cases. The grouping assertion matters because a list of cases in a configuration file has little value if the scheduler does something different with it. These assertions cover specific inputs and the configured suite. They leave open how a second independently launched suite might interact with it, whether a test outside the group touches shared scratch state, and whether setup and cleanup leave the state each test expects.
Read the run as an execution result
A backend CI job on the pull request revision completed its parallel test invocation with 2,611 passes, one skip and 14 expected failures. That is an observed result for the configured job. The merge source shows the design, and the job record shows an execution at the pull request head. The result does not measure how often tests collided before the change, or how often they might collide in another setup. It also leaves open whether selecting more processes would produce a result sooner. Parallel scheduling, database creation and competition for shared resources can all affect the time a contributor waits for a verdict.
The practical question to take into another suite is where each test reads and writes state. If it uses the fixture's working database, a process-specific copy may be the boundary it needs. If it reaches scratch state that another case can also use, the scheduling decision deserves its own test. A further comparison would record setup and execution separately and check for state leakage deliberately. Our source and the CI job give us a concrete starting point for that comparison, with a clear distinction between what was configured and what the one run established.
← All engineering articles