Skip to content

Commit 941068f

Browse files
authored
Alter chaos multiprocessing start method (#3149)
The previous fix of using get_context(method) is no longer working. To remedy this, switching to a fixture that sets the multiprocessing start method instead. python/cpython#132898 https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process ##### Short description: ##### More details: ##### What this PR does / why we need it: ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: ##### jira-ticket: <!-- full-ticket-url needs to be provided. This would add a link to the pull request to the jira and close it when the pull request is merged If the task is not tracked by a Jira ticket, just write "NONE". --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added a new fixture to chaos test suites to enforce a fork-based multiprocessing start method during test runs. * Enabled this fixture across migration, snapshot, and standard test modules to standardize behavior. * Updated test utilities to use the standard multiprocessing process construction for more consistent, more reliable test execution. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent b7ba173 commit 941068f

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎tests/chaos/conftest.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,14 @@ def deleted_pod_by_name_prefix(admin_client, cnv_pod_deletion_test_matrix__class
406406
namespace=pod_deletion_config["namespace_name"],
407407
pod_prefix=pod_deletion_config["pod_prefix"],
408408
)
409+
410+
411+
@pytest.fixture(scope="module")
412+
def multiprocessing_start_method_fork():
413+
# Use fork context to avoid pickling issues with nested functions
414+
# https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process
415+
# https://github.com/python/cpython/issues/132898
416+
original_start_method = multiprocessing.get_start_method()
417+
multiprocessing.set_start_method("fork", force=True)
418+
yield
419+
multiprocessing.set_start_method(original_start_method, force=True)

‎tests/chaos/migration/test_migration.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
pytestmark = [
2929
pytest.mark.chaos,
30-
pytest.mark.usefixtures("chaos_namespace", "cluster_monitoring_process"),
30+
pytest.mark.usefixtures("multiprocessing_start_method_fork", "chaos_namespace", "cluster_monitoring_process"),
3131
]
3232

3333

‎tests/chaos/snapshot/test_snapshot.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
pytest.mark.gpfs,
1212
pytest.mark.usefixtures(
1313
"skip_if_no_storage_class_for_snapshot",
14+
"multiprocessing_start_method_fork",
1415
"chaos_namespace",
1516
"cluster_monitoring_process",
1617
),

‎tests/chaos/standard/test_standard.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
pytestmark = [
1717
pytest.mark.chaos,
18-
pytest.mark.usefixtures("chaos_namespace", "cluster_monitoring_process", "skip_on_aws_cluster"),
18+
pytest.mark.usefixtures(
19+
"multiprocessing_start_method_fork", "chaos_namespace", "cluster_monitoring_process", "skip_on_aws_cluster"
20+
),
1921
]
2022

2123

‎tests/chaos/utils.py‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import time
77
from contextlib import contextmanager
88
from datetime import datetime
9-
from multiprocessing.context import ForkContext
109

1110
from kubernetes.dynamic.exceptions import ResourceNotFoundError
1211
from ocp_resources.deployment import Deployment
@@ -45,9 +44,6 @@
4544
)
4645
from utilities.virt import VirtualMachineForTests, fedora_vm_body, running_vm
4746

48-
# Use fork context to avoid pickling issues with nested functions
49-
_FORK_CONTEXT: ForkContext = multiprocessing.get_context("fork")
50-
5147
LOGGER = logging.getLogger(__name__)
5248

5349

@@ -135,7 +131,7 @@ def _delete_pods_continuously(_client, pod_prefix, namespace_name, ratio, interv
135131
except TimeoutExpiredError:
136132
LOGGER.info("Pod deleting process finished.")
137133

138-
return _FORK_CONTEXT.Process(
134+
return multiprocessing.Process(
139135
name="pod_delete",
140136
target=_delete_pods_continuously,
141137
args=(
@@ -189,7 +185,7 @@ def _monitor_nginx_server(
189185
time.sleep(_sampling_interval)
190186
LOGGER.info("HTTP querying finished successfully.")
191187

192-
return _FORK_CONTEXT.Process(
188+
return multiprocessing.Process(
193189
name="nginx_monitoring",
194190
target=_monitor_nginx_server,
195191
args=(
@@ -320,7 +316,7 @@ def _monitor_cluster():
320316
)
321317
time.sleep(interval)
322318

323-
return _FORK_CONTEXT.Process(
319+
return multiprocessing.Process(
324320
name="cluster_monitoring",
325321
target=_monitor_cluster,
326322
)

0 commit comments

Comments
 (0)