Skip to content

throughput_load_driver_test.py fails on macOS — same spawn/fork root cause as #5883, in a different module #7243

Open

Description

@shreyaskommuri

Describe the Bug

tests/scripts/throughput_load_driver_test.py fails deterministically on macOS (6 of 7
tests), even when run via the project's own documented test invocation
(python -m unittest tests.scripts.throughput_load_driver_test). This is the same root
cause as #5883 ("Certain Benchmarks Fail to Run on macOS"), in a different part of the
codebase that the fix for #5883 (PR #6055) doesn't reach.

throughput_load_driver.BurstRequestsOverTime dispatches work via
multiprocessing.Process(target=_TimeCommand, ...) (throughput_load_driver.py:263).
The tests mock the module-level _RunCommand function so _TimeCommand returns fake data
instead of actually running a shell command. On macOS, Python's default
multiprocessing start method is spawn, not fork: a spawn-started child process is a
brand-new Python interpreter that re-imports throughput_load_driver from scratch, so it
never sees the test's mock.patch.object(throughput_load_driver, '_RunCommand', ...) — that
patch only exists in the parent test process's memory. The child calls the real
_RunCommand, which tries to run a nonexistent/empty command, crashes inside the child
process, and never puts a result on the output queue. Every test that asserts on the number
or content of returned responses sees an empty/short list instead.

PR #6055 fixed the exact same mechanism for a real benchmark run (container_service.py,
kubernetes_hpa) by forcing fork on macOS — but it did so inside pkb.py's Main()
(perfkitbenchmarker/pkb.py:2068), which the unit test suite never calls. So the underlying
bug is already fixed for a real pkb.py invocation, but still live for anything that invokes
throughput_load_driver (or similar multiprocessing-based code) directly, including this
test file.

Steps to Reproduce

Version/context: local checkout of GoogleCloudPlatform/PerfKitBenchmarker master
(0c9e8620e), macOS, Python 3.14.4.

python -m unittest tests.scripts.throughput_load_driver_test -v

Result: FAILED (failures=6) — e.g. testWaitDoesntTriggerError fails with
AssertionError: [] has length of 0, expected 10.

Minimal reproduction of the actual mechanism, independent of the test file, confirming the
mock never reaches the spawned child:

import multiprocessing
from unittest import mock
from perfkitbenchmarker.scripts import throughput_load_driver as t

def fake(command):
    return 'MOCKED', '', 0

with mock.patch.object(t, '_RunCommand', side_effect=fake):
    q = multiprocessing.Queue()
    p = multiprocessing.Process(target=t._TimeCommand, args=('irrelevant', q))
    p.start()
    p.join(5)
    print('child exitcode:', p.exitcode)   # -> 1
    print('queue empty:', q.empty())        # -> True

The child process traceback shows it calling the real _RunCommand → real subprocess.run
→ FileNotFoundError: [Errno 2] No such file or directory: 'irrelevant', confirming the
mock never propagated into the spawned child.

Also confirmed multiprocessing.get_start_method() returns 'spawn' on this machine by
default, matching the documented cause of #5883.

Expected Behavior

throughput_load_driver_test.py should pass under the project's documented test invocation
on macOS, the same as it presumably does on Linux (where fork is the traditional default).

Additional Context

Not a duplicate of #5883 — that issue and its fix (PR #6055) only touched
container_service.py/pkb.py's CLI entrypoint; this is the same underlying
spawn-vs-fork mechanism surfacing in a different module/test file that the entrypoint-level
fix doesn't cover.

Happy to open a small PR applying the same pattern PR #6055 already established (gate
multiprocessing.set_start_method('fork', force=True) on platform.system() == 'Darwin'),
likely in the shared tests/pkb_common_test_case.py base test class so any future
multiprocessing-based test gets the same protection, not just this one file. Wanted to check
the right location before writing it.

AI was used for context and guidance while investigating and drafting this report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions