feat: command timeouts (#2898)

This commit is contained in:
Valentin Maerten
2026-08-11 22:09:25 +02:00
committed by GitHub
parent 993508c782
commit 37898d9102
21 changed files with 830 additions and 50 deletions

View File

@@ -27,3 +27,15 @@ tasks:
child:
cmds:
- cmd: echo "child {{.VAR1}}"
parent-with-timeout:
cmds:
- defer:
task: slow-cleanup
silent: true
timeout: 100ms
- echo 'parent completed'
slow-cleanup:
cmds:
- sleep 1 && echo 'cleanup completed'

26
testdata/dep_timeout/Taskfile.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
version: '3'
silent: true
tasks:
timeout-exceeded:
deps:
- task: slow
timeout: 300ms
cmds:
- echo "should not be reached"
timeout-not-exceeded:
deps:
- task: quick
timeout: 5s
cmds:
- echo "reached the end"
slow:
cmds:
- sleep 10
quick:
cmds:
- echo "quick"

View File

@@ -23,3 +23,9 @@ tasks:
cmds:
- defer: echo FOO={{.FOO}} - DYNAMIC_FOO={{.DYNAMIC_FOO}} - {{.PREFIX}}{{.EXIT_CODE}}
- exit 1
exit-timeout:
cmds:
- defer: echo {{.PREFIX}}{{.EXIT_CODE}}
- cmd: sleep 10
timeout: 200ms

View File

@@ -18,3 +18,23 @@ tasks:
cmd-should-fail:
cmds:
- cmd: exit 1
task-timeout-should-pass:
cmds:
- cmd: sleep 10
timeout: 200ms
- echo "reached the end"
ignore_error: true
cmd-timeout-should-pass:
cmds:
- cmd: sleep 10
timeout: 200ms
ignore_error: true
- echo "reached the end"
cmd-timeout-should-fail:
cmds:
- cmd: sleep 10
timeout: 200ms
- echo "reached the end"

18
testdata/run_once_failure/Taskfile.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
version: '3'
silent: true
tasks:
default:
cmds:
- task: shared
ignore_error: true
# Joins the finished execution, and must inherit its error.
- task: shared
- echo "should not be reached"
shared:
run: once
cmds:
- echo "shared ran"
- exit 1

27
testdata/run_once_timeout/Taskfile.yml vendored Normal file
View File

@@ -0,0 +1,27 @@
version: '3'
silent: true
tasks:
default:
# Without failfast the run waits for `owner` anyway, hiding what is tested.
failfast: true
deps: [owner, joiner]
# Holds the shared task far longer than `joiner` waits, so `joiner` reaches
# the deduplication path while it is still running.
owner:
cmds:
- task: shared
joiner:
cmds:
- sleep 0.2
- task: shared
timeout: 500ms
- echo "should not be reached"
shared:
run: once
cmds:
- sleep 10

57
testdata/timeout/Taskfile.yml vendored Normal file
View File

@@ -0,0 +1,57 @@
version: '3'
tasks:
timeout-exceeded:
desc: Command that should timeout
cmds:
- cmd: sleep 10
timeout: 1s
timeout-not-exceeded:
desc: Command that completes within timeout
cmds:
- cmd: echo "quick command"
timeout: 5s
no-timeout:
desc: Command with no timeout specified
cmds:
- echo "no timeout"
multiple-cmds-timeout:
desc: Multiple commands where one exceeds its timeout
cmds:
- cmd: echo "first"
timeout: 1s
- cmd: sleep 10
timeout: 1s
- cmd: echo "third"
timeout: 1s
slow-if-condition:
desc: Condition that hangs must be bounded by the command timeout
cmds:
- cmd: echo "condition was met"
if: sleep 10
timeout: 500ms
inherited-timeout:
desc: Calls a task whose command declares no timeout of its own
cmds:
- task: slow-without-timeout
timeout: 500ms
slow-without-timeout:
cmds:
- sleep 10
larger-child-timeout:
desc: Calls a task whose command declares a timeout it never reaches
cmds:
- task: slow-with-larger-timeout
timeout: 500ms
slow-with-larger-timeout:
cmds:
- cmd: sleep 10
timeout: 10m