diff --git a/rllib/tests/test_env_with_subprocess.py b/rllib/tests/test_env_with_subprocess.py index d0dcb17f8..195963c7b 100644 --- a/rllib/tests/test_env_with_subprocess.py +++ b/rllib/tests/test_env_with_subprocess.py @@ -2,12 +2,12 @@ import os import subprocess import tempfile -import time import ray from ray.tune import run_experiments from ray.tune.registry import register_env from ray.rllib.examples.env.env_with_subprocess import EnvWithSubprocess +from ray.test_utils import wait_for_condition def leaked_processes(): @@ -56,13 +56,11 @@ if __name__ == "__main__": }, }, }) - time.sleep(10.0) # Check whether processes are still running or Env has not cleaned up # the given tmp files. - leaked = leaked_processes() - assert not leaked, "LEAKED PROCESSES: {}".format(leaked) - assert not os.path.exists(tmp1), "atexit handler not called" - assert not os.path.exists(tmp2), "atexit handler not called" - assert not os.path.exists(tmp3), "close not called" - assert not os.path.exists(tmp4), "close not called" + wait_for_condition(lambda: not leaked_processes(), timeout=30) + wait_for_condition(lambda: not os.path.exists(tmp1), timeout=30) + wait_for_condition(lambda: not os.path.exists(tmp2), timeout=30) + wait_for_condition(lambda: not os.path.exists(tmp3), timeout=30) + wait_for_condition(lambda: not os.path.exists(tmp4), timeout=30) print("OK")