mirror of
https://github.com/krkn-chaos/krkn.git
synced 2026-08-25 09:27:36 +00:00
fix: serialize node network chaos tests to prevent xdist race condition (#1569)
* fix: serialize node network chaos tests to prevent xdist race condition Node network chaos tests share mutable tc rules on the same KinD worker node. Under pytest-xdist parallel execution, concurrent tests interfere with each other's tc state causing intermittent marker assertion failures. Pin all TestNodeNetworkChaos tests to a single xdist worker via xdist_group marker and switch dist mode to loadgroup so the marker is respected. Other test classes remain freely distributed. Signed-off-by: ddjain <darjain@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com> * fix: move --dist loadgroup from pytest.ini to invocation sites Keeping --dist loadgroup in pytest.ini addopts makes pytest fail at argument parsing when xdist is not installed, bypassing the preflight fixture's graceful skip message. Move the flag to the three places that already pass -n (Makefile test/test-fast, CI workflow) and update the README parallel-run example accordingly. Signed-off-by: ddjain <darjain@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com> --------- Signed-off-by: ddjain <darjain@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -53,7 +53,7 @@ jobs:
|
||||
- name: Run tests_v2
|
||||
run: |
|
||||
KRKN_TEST_COVERAGE=1 python -m pytest CI/tests_v2/ -v --timeout=300 --reruns=1 --reruns-delay=5 \
|
||||
--html=CI/tests_v2/report.html -n auto --junitxml=CI/tests_v2/results.xml
|
||||
--html=CI/tests_v2/report.html -n auto --dist loadgroup --junitxml=CI/tests_v2/results.xml
|
||||
|
||||
- name: Upload tests_v2 artifacts
|
||||
if: always()
|
||||
|
||||
@@ -75,10 +75,10 @@ preflight:
|
||||
|
||||
test: preflight
|
||||
cd $(REPO_ROOT) && KRKN_TEST_COVERAGE=1 $(PYTHON) -m pytest $(TESTS_DIR)/ -v --timeout=300 --reruns=2 --reruns-delay=10 \
|
||||
--html=$(TESTS_DIR)/report.html -n auto --junitxml=$(TESTS_DIR)/results.xml
|
||||
--html=$(TESTS_DIR)/report.html -n auto --dist loadgroup --junitxml=$(TESTS_DIR)/results.xml
|
||||
|
||||
test-fast: preflight
|
||||
cd $(REPO_ROOT) && $(PYTHON) -m pytest $(TESTS_DIR)/ -v -p no:rerunfailures -n auto --timeout=120
|
||||
cd $(REPO_ROOT) && $(PYTHON) -m pytest $(TESTS_DIR)/ -v -p no:rerunfailures -n auto --dist loadgroup --timeout=120
|
||||
|
||||
test-debug: preflight
|
||||
cd $(REPO_ROOT) && $(PYTHON) -m pytest $(TESTS_DIR)/ -v -s -p no:rerunfailures --timeout=300 \
|
||||
|
||||
@@ -89,7 +89,7 @@ pytest CI/tests_v2/ -v --timeout=300 --reruns=2 --reruns-delay=10 --html=CI/test
|
||||
### Run in parallel (faster suite)
|
||||
|
||||
```bash
|
||||
pytest CI/tests_v2/ -v -n 4 --timeout=300
|
||||
pytest CI/tests_v2/ -v -n 4 --dist loadgroup --timeout=300
|
||||
```
|
||||
|
||||
Ephemeral namespaces make tests parallel-safe; use `-n` with the number of workers (e.g. 4).
|
||||
|
||||
@@ -19,4 +19,5 @@ markers =
|
||||
namespace_deletion: marks a test as a namespace deletion (service_disruption) scenario test
|
||||
no_workload: skip workload deployment for this test (e.g. negative tests)
|
||||
order: set test order (pytest-order)
|
||||
xdist_group: assign tests to a named xdist group so they run on the same worker (no parallel tc conflicts)
|
||||
junit_family = xunit2
|
||||
|
||||
@@ -40,6 +40,7 @@ TEST_DURATION = 30
|
||||
|
||||
@pytest.mark.functional
|
||||
@pytest.mark.node_network_chaos
|
||||
@pytest.mark.xdist_group("node_network_chaos")
|
||||
class TestNodeNetworkChaos(BaseScenarioTest):
|
||||
"""Node network chaos: packet loss, latency, bandwidth, direction, targeting, safety, cleanup."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user