Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions src/toil/test/utils/utilsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -390,28 +402,31 @@ 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",
status_fn=ToilStatus.getPIDStatus,
process=wf,
seconds=60,
)
release_file.touch()
wf.wait()
self.check_status(
jobstore,
Expand Down