Commit dbd432c
authored
[BUG] race condition in OpenMLSplitTest when running tests in parallel (#1643)
## Problem
When running tests in parallel with pytest-xdist (e.g., "pytest -n 3
tests/test_tasks/test_split.py"), one test under OpenMLSplitTest fails
intermittently with an EOFError during pickle.load().
This was identified in CI job/63346513831 and reproduces roughly 1 out
of 10 runs locally.
## Analysis
The root cause is that all test instances share the same pickle cache
file path (`self.pd_filename`). When multiple workers run concurrently:
1. Worker A creates the pickle cache file during test execution
2. Worker B reads the pickle cache file
3. Worker A's tearDown() deletes the file
4. Worker B's pickle.load() encounters a partially deleted file →
EOFError
This is a classic race condition on shared filesystem state.
## Solution
Use `tempfile.mkdtemp()` to create a unique temporary directory for each
test instance, then copy the ARFF source file there. This ensures:
- Each test worker has its own isolated pickle cache file
- No shared state between parallel workers
- Automatic cleanup via shutil.rmtree() in tearDown()
The fix is minimal (10 insertions, 3 deletions) and doesn't change the
test logic - only the test isolation mechanism.
## Benchmarks / Testing
Ran 5 consecutive parallel test executions:
```
pytest -n 4 tests/test_tasks/test_split.py # 5 times
```
All 15 test runs (3 tests × 5 runs) passed successfully. Before the fix,
failures occurred ~10% of the time with parallel execution.
Fixes #16411 parent 7feb2a3 commit dbd432c
1 file changed
Lines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | | - | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
| 42 | + | |
35 | 43 | | |
36 | | - | |
| 44 | + | |
37 | 45 | | |
38 | | - | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| |||
0 commit comments