Skip to content

Commit

Permalink
Add subshell to hide resource monitor (#5091)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
adamnovak and github-actions[bot] authored Sep 16, 2024
1 parent 3c4b121 commit 8faca0f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/toil/test/wdl/testfiles/wait.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version 1.0

workflow wait {
input {
}

call waiter_task {
input:
}

output {
String result = read_lines(waiter_task.out)[0]
}
}

task waiter_task {
input {
}

command <<<
sleep 10 &
sleep 2 &
wait
echo "waited"
>>>

output {
File out = stdout()
}

runtime {
docker: "ubuntu:22.04"
}
}
16 changes: 16 additions & 0 deletions src/toil/test/wdl/wdltoil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from toil.fileStores import FileID
from toil.provisioners import cluster_factory
from toil.test import (ToilTest,
needs_docker,
needs_docker_cuda,
needs_google_storage,
needs_singularity_or_docker,
Expand Down Expand Up @@ -165,6 +166,21 @@ def test_url_to_file(self):
assert 'url_to_file.first_line' in result
assert isinstance(result['url_to_file.first_line'], str)
self.assertEqual(result['url_to_file.first_line'], 'chr1\t248387328')

@needs_docker
def test_wait(self):
"""
Test if Bash "wait" works in WDL scripts.
"""
wdl = os.path.abspath('src/toil/test/wdl/testfiles/wait.wdl')

result_json = subprocess.check_output(
self.base_command + [wdl, '-o', self.output_dir, '--logInfo', '--retryCount=0', '--wdlContainer=docker'])
result = json.loads(result_json)

assert 'wait.result' in result
assert isinstance(result['wait.result'], str)
self.assertEqual(result['wait.result'], 'waited')

def test_url_to_optional_file(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/toil/wdl/wdltoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,8 @@ def add_injections(self, command_string: str, task_container: TaskContainer) ->
}
""")
parts.append(script)
parts.append(f"_toil_resource_monitor {self.INJECTED_MESSAGE_DIR} &")
# Launch in a subshell so that it doesn't interfere with Bash "wait" in the main shell
parts.append(f"(_toil_resource_monitor {self.INJECTED_MESSAGE_DIR} &)")

if isinstance(task_container, SwarmContainer) and platform.system() == "Darwin":
# With gRPC FUSE file sharing, files immediately downloaded before
Expand Down

0 comments on commit 8faca0f

Please sign in to comment.