Skip to content

Fix race condition in Python tests by disabling async ECL output#6491

Merged
akva2 merged 2 commits intoOPM:masterfrom
hakonhagland:fix_test_errors
Sep 23, 2025
Merged

Fix race condition in Python tests by disabling async ECL output#6491
akva2 merged 2 commits intoOPM:masterfrom
hakonhagland:fix_test_errors

Conversation

@hakonhagland
Copy link
Contributor

@hakonhagland hakonhagland commented Sep 22, 2025

Thanks to @akva2 for reporting this issue: Sometimes running Python unit tests left misplaced output files (like SPE1CASE2_GASWATER.UNRST) and error message like:

Error: [/tmp/opm/opm-common/opm/io/eclipse/EclFile.cpp:243] Could not open file: './SPE1CASE2_GASWATER.UNRST'
ERROR: Uncaught std::exception when running tasklet: [/tmp/opm/opm-common/opm/io/eclipse/EclFile.cpp:243] Could not open file: './
SPE1CASE2_GASWATER.UNRST'.

The problem is that:

  • Tests use pushd() to change directory before running simulations
  • Simulator dispatches async tasklets to write ECL output files
  • pushd context exits before the async writes complete
  • Tasklets write files in wrong directory (build/python/ instead of build/python/test_data/<case>/)
  • Causes confusing error messages and misplaced output files

This PR adds --enable-async-ecl-output=false to all Python simulator tests to prevent race condition between async file writing tasklets and pushd context manager.

Add --enable-async-ecl-output=false to all Python simulator tests to prevent
race condition between async file writing tasklets and pushd context manager.

Problem:
- Tests use pushd() to change directory before running simulations
- Simulator dispatches async tasklets to write ECL output files
- pushd context exits before async writes complete
- Tasklets write files in wrong directory (build/python/ instead of test_data/)
- Causes confusing error messages and misplaced output files

Solution:
- Disable async ECL output during tests for deterministic behavior
- Files now created in correct locations within test_data/ directories
- Eliminates "Can not open EclFile" errors in logs
- Makes test execution predictable and synchronous
@hakonhagland hakonhagland added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Sep 22, 2025
@hakonhagland
Copy link
Contributor Author

jenkins build this please

Move simulator instantiation to factory functions that automatically
disable async ECL output. This prevents future contributors from
forgetting the --enable-async-ecl-output=false flag.

- Add create_black_oil_simulator/create_gas_water_simulator to pytest_common
- Define ENABLE_ASYNC_ECL_OUTPUT_FLAG constant
- Update all tests to use factory functions
- No functional changes, pure refactoring
@hakonhagland
Copy link
Contributor Author

jenkins build this please

Copy link
Member

@akva2 akva2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. This (in combination with #6488) makes tests stable again.

@akva2 akva2 merged commit 8f170d3 into OPM:master Sep 23, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants