1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Figuring out how GNU timeout works.
|
4 | #
|
5 | # Usage:
|
6 | # soil/timeout-test.sh <function name>
|
7 |
|
8 | set -o nounset
|
9 | set -o pipefail
|
10 | set -o errexit
|
11 |
|
12 | source test/common.sh
|
13 |
|
14 | test-simple() {
|
15 | time timeout 0.1 sleep 10
|
16 | }
|
17 |
|
18 | one() {
|
19 | echo "- sleep 0.$1 in pid $$"
|
20 | sleep 0.$1
|
21 | }
|
22 |
|
23 | many() {
|
24 | seq 5 8 | xargs -n 1 -P 3 $0 one
|
25 | }
|
26 |
|
27 | test-xargs() {
|
28 | local pid=$$
|
29 | set +o errexit
|
30 |
|
31 | # This shows the full process tree
|
32 | $0 many &
|
33 |
|
34 | #timeout 0.1 $0 many &
|
35 |
|
36 | sleep 0.1
|
37 | pstree --ascii -p $pid
|
38 |
|
39 | echo 'Any sleep processes alive?'
|
40 | pgrep sleep
|
41 |
|
42 | wait
|
43 | echo status=$?
|
44 | }
|
45 |
|
46 | all() {
|
47 | run-test-funcs
|
48 | }
|
49 |
|
50 | "$@"
|