Skip to content

Commit ead94fc

Browse files
committed
Add test case
Signed-off-by: Ivan Santiago Paunovic <[email protected]>
1 parent ff285e0 commit ead94fc

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

launch/test/launch/test_execute_local.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717

1818
"""Tests for the ExecuteLocal Action."""
1919

20+
import asyncio
2021
import os
22+
import psutil
23+
import signal
2124
import sys
25+
import time
2226

2327
from launch import LaunchDescription
2428
from launch import LaunchService
@@ -28,6 +32,8 @@
2832
from launch.actions import TimerAction
2933
from launch.descriptions import Executable
3034

35+
import osrf_pycommon.process_utils
36+
3137
import pytest
3238

3339

@@ -124,3 +130,37 @@ def generate_launch_description():
124130
ls.include_launch_description(generate_launch_description())
125131
assert 0 == ls.run()
126132
assert expected_called_count == on_exit_callback.called_count
133+
134+
135+
PYTHON_SCRIPT="""\
136+
import time
137+
138+
while 1:
139+
time.sleep(0.5)
140+
"""
141+
142+
def test_kill_subprocesses():
143+
"""Test launching a process with an environment variable."""
144+
executable = ExecuteLocal(
145+
process_description=Executable(
146+
cmd=['python3', '-c', f'"{PYTHON_SCRIPT}"'],
147+
),
148+
shell=True,
149+
output='screen',
150+
)
151+
ld = LaunchDescription([executable])
152+
ls = LaunchService()
153+
ls.include_launch_description(ld)
154+
loop = asyncio.new_event_loop()
155+
asyncio.set_event_loop(loop)
156+
run_async_task = loop.create_task(ls.run_async())
157+
async def wait_for_subprocesses():
158+
start = time.time()
159+
while len(psutil.Process().children(recursive=True)) != 2:
160+
await asyncio.sleep(0.5)
161+
assert time.time() < start + 5., 'timed out waiting for processes to setup'
162+
wait_for_subprocesses_task = loop.create_task(wait_for_subprocesses())
163+
loop.run_until_complete(wait_for_subprocesses_task)
164+
os.kill(executable.process_details['pid'], signal.SIGTERM)
165+
loop.run_until_complete(run_async_task)
166+
assert len(psutil.Process().children(recursive=True)) == 0

0 commit comments

Comments
 (0)