Show More
@@ -1,36 +1,39 | |||||
1 | #!/bin/sh |
|
1 | #!/bin/sh | |
2 | # |
|
2 | # | |
3 | # wait up to TIMEOUT seconds until a WAIT_ON_FILE is created. |
|
3 | # wait up to TIMEOUT seconds until a WAIT_ON_FILE is created. | |
4 | # |
|
4 | # | |
5 | # In addition, this script can create CREATE_FILE once it is ready to wait. |
|
5 | # In addition, this script can create CREATE_FILE once it is ready to wait. | |
6 |
|
6 | |||
7 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then |
|
7 | if [ $# -lt 2 ] || [ $# -gt 3 ]; then | |
8 | echo $# |
|
8 | echo $# | |
9 | echo "USAGE: $0 TIMEOUT WAIT_ON_FILE [CREATE_FILE]" |
|
9 | echo "USAGE: $0 TIMEOUT WAIT_ON_FILE [CREATE_FILE]" | |
10 | fi |
|
10 | fi | |
11 |
|
11 | |||
12 | timer="$1" |
|
12 | timer="$1" | |
13 |
|
13 | |||
14 | # if the test timeout have been extended, explicitly extend the provided timer |
|
14 | # Scale the timeout to match the sleep steps below, i.e. 1/0.02. | |
|
15 | timer=$(( 50 * $timer )) | |||
|
16 | # If the test timeout have been extended, also scale the timer relative | |||
|
17 | # to the normal timing. | |||
15 | if [ "$HGTEST_TIMEOUT_DEFAULT" -lt "$HGTEST_TIMEOUT" ]; then |
|
18 | if [ "$HGTEST_TIMEOUT_DEFAULT" -lt "$HGTEST_TIMEOUT" ]; then | |
16 |
timer=$(( ( |
|
19 | timer=$(( ( $timer * $HGTEST_TIMEOUT) / $HGTEST_TIMEOUT_DEFAULT )) | |
17 | fi |
|
20 | fi | |
18 |
|
21 | |||
19 | wait_on="$2" |
|
22 | wait_on="$2" | |
20 | create="" |
|
23 | create="" | |
21 | if [ $# -eq 3 ]; then |
|
24 | if [ $# -eq 3 ]; then | |
22 | create="$3" |
|
25 | create="$3" | |
23 | fi |
|
26 | fi | |
24 |
|
27 | |||
25 | if [ -n "$create" ]; then |
|
28 | if [ -n "$create" ]; then | |
26 | touch "$create" |
|
29 | touch "$create" | |
27 | create="" |
|
30 | create="" | |
28 | fi |
|
31 | fi | |
29 | while [ "$timer" -gt 0 ] && [ ! -f "$wait_on" ]; do |
|
32 | while [ "$timer" -gt 0 ] && [ ! -f "$wait_on" ]; do | |
30 | timer=$(( $timer - 1)) |
|
33 | timer=$(( $timer - 1)) | |
31 |
sleep 0.0 |
|
34 | sleep 0.02 | |
32 | done |
|
35 | done | |
33 | if [ "$timer" -le 0 ]; then |
|
36 | if [ "$timer" -le 0 ]; then | |
34 | echo "file not created after $1 seconds: $wait_on" >&2 |
|
37 | echo "file not created after $1 seconds: $wait_on" >&2 | |
35 | exit 1 |
|
38 | exit 1 | |
36 | fi |
|
39 | fi |
General Comments 0
You need to be logged in to leave comments.
Login now