mirror of
https://github.com/go-task/task.git
synced 2026-09-02 04:02:08 +02:00
feat: command timeouts (#2898)
This commit is contained in:
12
testdata/deferred/Taskfile.yml
vendored
12
testdata/deferred/Taskfile.yml
vendored
@@ -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
26
testdata/dep_timeout/Taskfile.yml
vendored
Normal 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"
|
||||
6
testdata/exit_code/Taskfile.yml
vendored
6
testdata/exit_code/Taskfile.yml
vendored
@@ -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
|
||||
|
||||
20
testdata/ignore_errors/Taskfile.yml
vendored
20
testdata/ignore_errors/Taskfile.yml
vendored
@@ -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
18
testdata/run_once_failure/Taskfile.yml
vendored
Normal 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
27
testdata/run_once_timeout/Taskfile.yml
vendored
Normal 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
57
testdata/timeout/Taskfile.yml
vendored
Normal 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
|
||||
Reference in New Issue
Block a user