diff --git a/src/toil/test/utils/utilsTest.py b/src/toil/test/utils/utilsTest.py index 3b79517278..e41060b046 100644 --- a/src/toil/test/utils/utilsTest.py +++ b/src/toil/test/utils/utilsTest.py @@ -48,6 +48,18 @@ logger = logging.getLogger(__name__) +def wait_for_file(file_path: str) -> None: + """Wait until a file exists.""" + while not os.path.exists(file_path): + time.sleep(0.1) + +def wait_for_file_workflow() -> None: + """Toil workflow that waits for the file in argument 2 to exist.""" + options = Job.Runner.getDefaultOptions(sys.argv[1]) + options.clean = "never" + Job.Runner.startToil(Job.wrapFn(wait_for_file, sys.argv[2]), options) + + @pytest.fixture(scope="function") def unsortedFile(tmp_path: Path) -> Generator[Path]: try: @@ -390,21 +402,23 @@ def check_status( current_status == status ), "Waited {seconds} seconds without status reaching {status}; stuck at {current_status}" - def testGetPIDStatus(self, tmp_path: Path, unsortedFile: Path) -> None: + def testGetPIDStatus(self, tmp_path: Path) -> None: """Test that ToilStatus.getPIDStatus() behaves as expected.""" jobstore = tmp_path / "jobstore" - outputFile = tmp_path / "someSortedStuff.txt" + release_file = tmp_path / "release-workflow" + assert __name__ != "__main__" + # Run wait_for_file_workflow() as a child process. wf = subprocess.Popen( [ python, - "-m", - "toil.test.sort.sort", - jobstore.as_uri(), - f"--fileToSort={unsortedFile}", - f"--outputFile={outputFile}", - "--clean=never", + "-c", + f"from {__name__} import " + f"wait_for_file_workflow as w; w()", + str(jobstore), + str(release_file), ] ) + # Check the status by PID self.check_status( jobstore, "RUNNING", @@ -412,6 +426,7 @@ def testGetPIDStatus(self, tmp_path: Path, unsortedFile: Path) -> None: process=wf, seconds=60, ) + release_file.touch() wf.wait() self.check_status( jobstore,