The inner workings of this framework is quite similar to that of pytest-xdist.
The RedQueen benchmark framework works by spawning one or more Pawn
s, which
are controlled by a Rook
. The communication between the Rook
and the Pawn
s
is managed by Knight
s. Furthermore, the Rook
must report results back to the
Queen
and the Bishop, which is responsible for storing those results. Each
Pawn
is responsible for collecting tests and running the tests assigned to it
by the Rook
.
A slightly more details of the working flow is as follows:
- The
Queen
initializes instances of aRook
and aBishop
. - At the beginning of the test session, the
Queen
tells theRook
how many pawns it should employ to run all tests. In turn, theRook
spawns the pawns as subprocesses. The communication between theRook
and thePawn
s is managed byKnight
objects and makes use ofPipe
s. - For technical reasons [1], each
Pawn
itself is a minipytest
runner. Whenever aPawn
is initialized, it performs an entire test collection and reports the number of collected tests back to theRook
. After that, a pawn must sit idle, waiting for commands.
(Note that the Rook
does not perform any collection itself.)
- After spawning all
Pawns
, it waits for all of them to report back with the total number of collected tests. - If all is well, the
Rook
distributes tests among the pawns by sending them indexes of the test they should execute. (This works because allPawn
s have the same collected list of tests.) - As the
Pawn
s start and complete tests, they report results back to theRook
through theKnight
s. In turn, theRook
forwards the results to theBishop
and the appropriatepytest
hooks (pytest_runtest_logstart
,pytest_runtest_logreport
, andpytest_runtest_logfinish
). The latter is essential topytest
be able to report progress. - The
Rook
assigns new tests toPawn
s when a test completes. When it runs out of tests to assign, it sends ashutdown
signal.
[1] If the collection of tests was performed by the Rook
, the Rook
would
have to serialize collected items to send them through the pipe, as Pawn
s
execute in other processes. However, those test items are not easy to serialize!
Furthermore, I believe that even if I managed to serialize test items, the
solution would be complex and fragile, as any slight change in pytest
might be
enough to break things.