Repository navigation
Fix multiprocessing on macOS for throughput_load_driver_test.py - #7244
Open
shreyaskommuri wants to merge 1 commit into
Open
shreyaskommuri wants to merge 1 commit into
shreyaskommuri wants to merge 1 commit into
Conversation
Same root cause as issue GoogleCloudPlatform#5883 / PR GoogleCloudPlatform#6055: Python's default multiprocessing start method is 'spawn' on macOS, not 'fork', so a multiprocessing.Process child is a fresh interpreter that re-imports the target module and never sees mock.patch() applied in the parent test process. throughput_load_driver's tests mock _RunCommand, but the real work runs inside multiprocessing.Process children, so on macOS they call the real _RunCommand, crash on a nonexistent command, and never report a result, failing 6 of 7 tests. PR GoogleCloudPlatform#6055 fixed this exact mechanism for real pkb.py runs by forcing 'fork' on macOS inside Main(), but the unit test suite never calls Main(). Apply the same fix at module level in the shared PkbCommonTestCase base, so any multiprocessing-based test gets the same protection, not just this one file. Fixes GoogleCloudPlatform#7243
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #7243.
tests/scripts/throughput_load_driver_test.pyfails 6 of its 7 tests onmacOS, even run via the documented
python -m unittestinvocation. Root cause isidentical to #5883 / PR #6055: Python's default
multiprocessingstart method isspawnon macOS, notfork. Aspawn-startedmultiprocessing.Processchild is abrand-new interpreter that re-imports its target module from scratch, so it never sees
a
mock.patch()applied in the parent process.throughput_load_driver's tests mock the module-level_RunCommand, but the actualwork happens inside
multiprocessing.Process(target=_TimeCommand, ...)children. OnmacOS those children call the real
_RunCommand, which tries to run anonexistent/empty command, crashes inside the child, and never reports a result —
so tests asserting on the number/content of responses see an empty list instead.
PR #6055 already fixed this exact mechanism for real
pkb.pybenchmark runs, byforcing
forkon macOS insidepkb.py'sMain(). The unit test suite never callsMain(), so that fix doesn't reach it.This applies the same fix (
multiprocessing.set_start_method('fork', force=True)gated on
platform.system() == 'Darwin') at module level intests/pkb_common_test_case.py, the shared base class every PKB test casesubclasses, rather than only in the one failing test file — so any future
multiprocessing-based test gets the same protection.
Also updates
CHANGES.next.mdperCONTRIBUTING.md.Test Plan
Before the fix, via the documented test invocation:
After the fix:
Checked for regressions:
tests/and every file undertests/scripts/via the documented per-file
python -m unittestinvocation. Onlymessaging_service_scripts_e2e_main_process_test.pyandmessaging_service_scripts_e2e_workers_test.pystill fail — confirmed viagit stashthat both fail identically with or without this change(
AttributeError: <module 'os'> does not have the attribute 'sched_setaffinity',a pre-existing, unrelated macOS-only gap: that syscall simply doesn't exist on
macOS. Out of scope for this fix.
pyink --pyink-indentation 2 --pyink-use-majority-quotes --unstable --line-length=80 --diff tests/pkb_common_test_case.py:the only reformat suggestions are in pre-existing, unrelated code further down the
file (confirmed present on a clean
mastercheckout too, viagit stash); none ofthe lines this PR adds are flagged.
git diff -U0 master | lint-diffs:pylint: mine=0, always=0.Additional Notes
I've signed the Google CLA. AI was used for context and guidance while investigating
and drafting this fix.