|
6 | 6 | # a subdirectory called "$git"
|
7 | 7 | TEST_NO_CREATE_REPO=NoThanks
|
8 | 8 |
|
| 9 | +# Some operations require multiple attempts to be successful. Define |
| 10 | +# here the maximal retry timeout in seconds. |
| 11 | +RETRY_TIMEOUT=60 |
| 12 | + |
9 | 13 | . ./test-lib.sh
|
10 | 14 |
|
11 | 15 | if ! test_have_prereq PYTHON
|
@@ -36,6 +40,15 @@ native_path() {
|
36 | 40 | echo "$path"
|
37 | 41 | }
|
38 | 42 |
|
| 43 | +# On Solaris the 'date +%s' function is not supported and therefore we |
| 44 | +# need this replacement. |
| 45 | +# Attention: This function is not safe again against time offset updates |
| 46 | +# at runtime (e.g. via NTP). The 'clock_gettime(CLOCK_MONOTONIC)' |
| 47 | +# function could fix that but it is not in Python until 3.3. |
| 48 | +time_in_seconds() { |
| 49 | + python -c 'import time; print int(time.time())' |
| 50 | +} |
| 51 | + |
39 | 52 | # Try to pick a unique port: guess a large number, then hope
|
40 | 53 | # no more than one of each test is running.
|
41 | 54 | #
|
@@ -121,22 +134,35 @@ p4_add_user() {
|
121 | 134 | EOF
|
122 | 135 | }
|
123 | 136 |
|
| 137 | +retry_until_success() { |
| 138 | + timeout=$(($(time_in_seconds) + $RETRY_TIMEOUT)) |
| 139 | + until "$@" 2>/dev/null || test $(time_in_seconds) -gt $timeout |
| 140 | + do |
| 141 | + sleep 1 |
| 142 | + done |
| 143 | +} |
| 144 | + |
| 145 | +retry_until_fail() { |
| 146 | + timeout=$(($(time_in_seconds) + $RETRY_TIMEOUT)) |
| 147 | + until ! "$@" 2>/dev/null || test $(time_in_seconds) -gt $timeout |
| 148 | + do |
| 149 | + sleep 1 |
| 150 | + done |
| 151 | +} |
| 152 | + |
124 | 153 | kill_p4d() {
|
125 | 154 | pid=$(cat "$pidfile")
|
126 |
| - # it had better exist for the first kill |
127 |
| - kill $pid && |
128 |
| - for i in 1 2 3 4 5 ; do |
129 |
| - kill $pid >/dev/null 2>&1 || break |
130 |
| - sleep 1 |
131 |
| - done && |
| 155 | + retry_until_fail kill $pid |
| 156 | + retry_until_fail kill -9 $pid |
132 | 157 | # complain if it would not die
|
133 | 158 | test_must_fail kill $pid >/dev/null 2>&1 &&
|
134 | 159 | rm -rf "$db" "$cli" "$pidfile"
|
135 | 160 | }
|
136 | 161 |
|
137 | 162 | cleanup_git() {
|
138 |
| - rm -rf "$git" && |
139 |
| - mkdir "$git" |
| 163 | + retry_until_success rm -r "$git" |
| 164 | + test_must_fail test -d "$git" && |
| 165 | + retry_until_success mkdir "$git" |
140 | 166 | }
|
141 | 167 |
|
142 | 168 | marshal_dump() {
|
|
0 commit comments