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
+
13
+ # Sometimes p4d seems to hang. Terminate the p4d process automatically after
14
+ # the defined timeout in seconds.
15
+ P4D_TIMEOUT=300
16
+
9
17
. ./test-lib.sh
10
18
11
19
if ! test_have_prereq PYTHON
@@ -36,6 +44,15 @@ native_path() {
36
44
echo " $path "
37
45
}
38
46
47
+ # On Solaris the 'date +%s' function is not supported and therefore we
48
+ # need this replacement.
49
+ # Attention: This function is not safe again against time offset updates
50
+ # at runtime (e.g. via NTP). The 'clock_gettime(CLOCK_MONOTONIC)'
51
+ # function could fix that but it is not in Python until 3.3.
52
+ time_in_seconds () {
53
+ python -c ' import time; print int(time.time())'
54
+ }
55
+
39
56
# Try to pick a unique port: guess a large number, then hope
40
57
# no more than one of each test is running.
41
58
#
@@ -57,6 +74,15 @@ cli="$TRASH_DIRECTORY/cli"
57
74
git=" $TRASH_DIRECTORY /git"
58
75
pidfile=" $TRASH_DIRECTORY /p4d.pid"
59
76
77
+ # Sometimes "prove" seems to hang on exit because p4d is still running
78
+ cleanup () {
79
+ if test -f " $pidfile "
80
+ then
81
+ kill -9 $( cat " $pidfile " ) 2> /dev/null && exit 255
82
+ fi
83
+ }
84
+ trap cleanup EXIT
85
+
60
86
# git p4 submit generates a temp file, which will
61
87
# not get cleaned up if the submission fails. Don't
62
88
# clutter up /tmp on the test machine.
@@ -81,6 +107,19 @@ start_p4d() {
81
107
# will be caught with the "kill -0" check below.
82
108
i=${P4D_START_PATIENCE:- 300}
83
109
pid=$( cat " $pidfile " )
110
+
111
+ timeout=$(( $(time_in_seconds) + $P4D_TIMEOUT ))
112
+ while true
113
+ do
114
+ if test $( time_in_seconds) -gt $timeout
115
+ then
116
+ kill -9 $pid
117
+ exit 1
118
+ fi
119
+ sleep 1
120
+ done &
121
+ watchdog_pid=$!
122
+
84
123
ready=
85
124
while test $i -gt 0
86
125
do
@@ -121,22 +160,36 @@ p4_add_user() {
121
160
EOF
122
161
}
123
162
163
+ retry_until_success () {
164
+ timeout=$(( $(time_in_seconds) + $RETRY_TIMEOUT ))
165
+ until " $@ " 2> /dev/null || test $( time_in_seconds) -gt $timeout
166
+ do
167
+ sleep 1
168
+ done
169
+ }
170
+
171
+ retry_until_fail () {
172
+ timeout=$(( $(time_in_seconds) + $RETRY_TIMEOUT ))
173
+ until ! " $@ " 2> /dev/null || test $( time_in_seconds) -gt $timeout
174
+ do
175
+ sleep 1
176
+ done
177
+ }
178
+
124
179
kill_p4d () {
125
180
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 &&
181
+ retry_until_fail kill $pid
182
+ retry_until_fail kill -9 $pid
132
183
# complain if it would not die
133
184
test_must_fail kill $pid > /dev/null 2>&1 &&
134
- rm -rf " $db " " $cli " " $pidfile "
185
+ rm -rf " $db " " $cli " " $pidfile " &&
186
+ retry_until_fail kill -9 $watchdog_pid
135
187
}
136
188
137
189
cleanup_git () {
138
- rm -rf " $git " &&
139
- mkdir " $git "
190
+ retry_until_success rm -r " $git "
191
+ test_must_fail test -d " $git " &&
192
+ retry_until_success mkdir " $git "
140
193
}
141
194
142
195
marshal_dump () {
0 commit comments