Skip to content

Fix OrderReporter producing empty test_order.log in parallel DRb mode#387

Closed
gmalette wants to merge 1 commit intomainfrom
gm/order-reporter-parallel-drb
Closed

Fix OrderReporter producing empty test_order.log in parallel DRb mode#387
gmalette wants to merge 1 commit intomainfrom
gm/order-reporter-parallel-drb

Conversation

@gmalette
Copy link
Copy Markdown
Contributor

@gmalette gmalette commented Apr 2, 2026

Situation

OrderReporter writes test identifiers in its before_test method, but in Rails parallel DRb mode (forked processes with parallelize(workers: N, with: :processes)), before_test is never called. The parallelization server only calls prerecord and record on the parent process's reporters. Since tests execute in forked workers via Minitest.run_one_method (which bypasses reporters entirely), test_order.log is truncated on start and never written to.

This makes it impossible to bisect order-dependent flaky test failures because the test order is never recorded.

Execution

The reporter API can't solve this alone: in DRb mode, prerecord/record run in the parent process with no worker identity, so we can't produce per-worker files from there.

Instead, we prepend a TestOrderTracking module onto Minitest::Test#before_setup, which fires inside the forked worker during run_one_method. There, Process.pid correctly identifies the worker.

Each forked worker writes to its own file (test_order.worker-{pid}.log) with sync writes enabled, since workers never call report and buffered writes risk data loss on crash. The parent's test_order.log is used in non-parallel mode where the parent runs tests directly. Stale worker files from previous runs are cleaned up on start.

To find which worker ran a failing test: grep test_name log/test_order.worker-*.log

@gmalette gmalette force-pushed the gm/order-reporter-parallel-drb branch 2 times, most recently from 97702b0 to 24ac7da Compare April 2, 2026 19:24
## Situation

OrderReporter writes test identifiers in its before_test method, but in
Rails parallel DRb mode (forked processes), before_test is never called.
The parallelization server only calls prerecord and record on the parent
process's reporters. Since tests execute in forked workers via
Minitest.run_one_method (which bypasses reporters entirely), the
test_order.log file is truncated on start and never written to.

This makes it impossible to bisect order-dependent flaky test failures
because the test order is never recorded.

## Execution

Instead of relying on the reporter API (which lacks worker identity in
DRb mode), prepend a TestOrderTracking module onto Minitest::Test that
hooks into before_setup. This fires inside the forked worker process
during run_one_method, where Process.pid correctly identifies the worker.

Each forked worker writes to its own file (test_order.worker-{pid}.log)
with sync writes enabled (workers never call report, so buffered writes
risk data loss on crash). The parent process's main test_order.log is
used in non-parallel mode where the parent is the test process.

On start, stale worker files from previous runs are cleaned up.
@gmalette gmalette force-pushed the gm/order-reporter-parallel-drb branch from 24ac7da to 14b8878 Compare April 2, 2026 19:34
@gmalette gmalette closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant