From 1f313073076c19c8cd3cde230cfa46fc3268c087 Mon Sep 17 00:00:00 2001 From: Aaron Heise Date: Sat, 18 Feb 2023 07:39:00 -0600 Subject: [PATCH] Test improvements --- tests/helpers.py | 15 ++++++++++++++- tests/test_process.py | 16 ++++++++-------- tests/test_rnsh.py | 4 ++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/helpers.py b/tests/helpers.py index 98170d6..53604b8 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,4 +1,5 @@ import logging +import time import types import typing import tempfile @@ -147,4 +148,16 @@ def test_config_and_cleanup(): assert filedata.index("acehoss test config") > 0 with pytest.raises(ValueError): filedata.index("22222") - assert not os.path.exists(os.path.join(td, "config")) \ No newline at end of file + assert not os.path.exists(os.path.join(td, "config")) + + +def wait_for_condition(condition: callable, timeout: float): + tm = time.time() + timeout + while tm > time.time() and not condition(): + time.sleep(0.01) + + +async def wait_for_condition_async(condition: callable, timeout: float): + tm = time.time() + timeout + while tm > time.time() and not condition(): + await asyncio.sleep(0.01) \ No newline at end of file diff --git a/tests/test_process.py b/tests/test_process.py index 27a1448..7f8ebe8 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -8,7 +8,7 @@ import multiprocessing.pool logging.getLogger().setLevel(logging.DEBUG) -# @pytest.mark.skip_ci +@pytest.mark.skip_ci @pytest.mark.asyncio async def test_echo(): """ @@ -30,7 +30,7 @@ async def test_echo(): assert not state.process.running -# @pytest.mark.skip_ci +@pytest.mark.skip_ci @pytest.mark.asyncio async def test_echo_live(): """ @@ -52,7 +52,7 @@ async def test_echo_live(): assert not state.process.running -# @pytest.mark.skip_ci +@pytest.mark.skip_ci @pytest.mark.asyncio async def test_echo_live_pipe_in(): """ @@ -74,7 +74,7 @@ async def test_echo_live_pipe_in(): assert not state.process.running -# @pytest.mark.skip_ci +@pytest.mark.skip_ci @pytest.mark.asyncio async def test_echo_live_pipe_out(): """ @@ -99,7 +99,7 @@ async def test_echo_live_pipe_out(): assert not state.process.running -# @pytest.mark.skip_ci +@pytest.mark.skip_ci @pytest.mark.asyncio async def test_echo_live_pipe_err(): """ @@ -121,7 +121,7 @@ async def test_echo_live_pipe_err(): assert not state.process.running -# @pytest.mark.skip_ci +@pytest.mark.skip_ci @pytest.mark.asyncio async def test_echo_live_pipe_out_err(): """ @@ -147,7 +147,7 @@ async def test_echo_live_pipe_out_err(): -# @pytest.mark.skip_ci +@pytest.mark.skip_ci @pytest.mark.asyncio async def test_echo_live_pipe_all(): """ @@ -170,7 +170,7 @@ async def test_echo_live_pipe_all(): assert not state.process.running -# @pytest.mark.skip_ci +@pytest.mark.skip_ci @pytest.mark.asyncio async def test_double_echo_live(): """ diff --git a/tests/test_rnsh.py b/tests/test_rnsh.py index a8ca610..b06abf5 100644 --- a/tests/test_rnsh.py +++ b/tests/test_rnsh.py @@ -62,7 +62,8 @@ async def get_id_and_dest(td: str) -> tuple[str, str]: await asyncio.sleep(0.1) assert wrapper.process.running # wait for process to start up - await asyncio.sleep(3) + await tests.helpers.wait_for_condition_async(lambda: not wrapper.process.running, 5) + assert not wrapper.process.running # read the output text = wrapper.read().decode("utf-8").replace("\r", "").replace("\n", "") assert text.index("Identity") is not None @@ -73,7 +74,6 @@ async def get_id_and_dest(td: str) -> tuple[str, str]: dh = match.group(2) assert len(dh) == 32 await asyncio.sleep(0.1) - assert not wrapper.process.running return ih, dh