Parameterized `launch_pytest` tests don't close node log files
Maintainers usually reply within 1 day
@wjwwood is already working on this.
Since Aug 22, 2024.
Assessment
This issue has not been assessed yet.
Description
Bug report
When @pytest.mark.parametrize is used in a function scope with launch_pytest the node log files from each test parameterization remain open even when execution of that specific parameterized test is complete. For large projects with dozens or hundreds of nodes this eventually causes a OSError: [Errno 24] Too many open files error.
Required Info:
- Operating System: Ubuntu Linux 20.04 amd64
- Installation type: source
- Version or commit hash: 9e517a3abd016367244fff9fa96ac8eae371a00b
- DDS implementation: RTI Connext
- Client library (if applicable): rclpy
Steps to reproduce issue
The code below cannot be run directly, but illustrates the issue. The TestContext object represents a specific test setup we want to run, and is constructed by name from a list of acceptable names in ALL_TEST_NAMES. This allows us to cherry-pick a subset of tests to run from our entire suite, with pytest -k or pytest --regex. The idea is each tests is run in sequence, against a new execution context and saved the results to a TEST_RESULTS data structure in the global context. When the test session ends, the AnalyzeResults function is called to analyze all results from all tests.
import pytest
import launch
import launch_pytest
from my_project.test_framework import TestContext, ALL_TEST_NAMES, AnalyzeResults
TEST_RESULTS = []
@pytest.fixture(scope='function')
def test_context(request):
test_context = TestContext(launch_test=request.param)
test_context.do_some_preprocessing_steps()
return test_context
@launch_pytest.fixture(scope='function')
def launch_description(test_context):
return launch.LaunchDescription(
test_context.get_all_actions() + [launch_pytest.actions.ReadyToTest()])
@pytest.mark.parametrize('test_context', ALL_TEST_NAMES, indirect=True)
@pytest.mark.launch(fixture=launch_description)
def test_execution(test_context):
results = test_context.do_some_post_postprocessing_steps()
TEST_RESULTS.append(results)
@pytest.fixture(scope='session', autouse=True)
def run_assertions():
yield
AnalyzeResults(TEST_RESULTS)
Expected behavior
Test completes without throwing an error.
Actual behavior
Python throws an internal error OSError: [Errno 24] Too many open files.
This only happens several tests into the sequence, pointing to the fact that something internally is not cleaning up after itself. I have painfully tracked lsof -p <pid_of_pytest_invocation> over time and realized that the ROS2 node log files created by each parameterized test are not being closed, even though the stack has shut down. So, let's say we have k nodes and therefore k log files created by ROS per launch test that is run. If I run n parameterized tests sequentially the number of log files open at test i, where i is in {1 ... n}, will be i * k.
Additional information
You can always increase the number of files that may be opened at once with ulimit but this is a bandaid and not a solution.
- Dominant language
- Python
- Stars
- 156
- Forks
- 200
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 11
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ros2/launch
-
Use a relative target for the `latest` log symlink so it survives different absolute mount paths (host/Docker)Possibly taken @Old-Ding claimed this 139 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ros2/launch#978 · 1 reaction ·
Maintainers usually reply within 1 day
-
Add OpaqueFunction to list at docs.ros.orgMay be free again A pull request for this issue was closed without being merged. Openbug help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ros2/launch#826 · 4 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
[launch_testing] pytest>8.1 dropped the legacy "path" argument from its internal hooks on humblePossibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 55/100
ros2/launch#979 · 6 comments ·
Maintainers usually reply within 1 day
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
hive size:simple
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
backend enhancement priority:P3
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
geolens-io/geolens#4161 ·
Maintainers usually reply within 1 day