##// END OF EJS Templates
tests: add timeouts, make run-tests.py clean up dead daemon processes...
Vadim Gelfer -
r2571:83cfd95e default
parent child Browse files
Show More
@@ -2649,7 +2649,7 b' def serve(ui, repo, **opts):'
2649
2649
2650 if opts['pid_file']:
2650 if opts['pid_file']:
2651 fp = open(opts['pid_file'], 'w')
2651 fp = open(opts['pid_file'], 'w')
2652 fp.write(str(os.getpid()))
2652 fp.write(str(os.getpid()) + '\n')
2653 fp.close()
2653 fp.close()
2654
2654
2655 if opts['daemon_pipefds']:
2655 if opts['daemon_pipefds']:
@@ -7,23 +7,32 b''
7 # This software may be used and distributed according to the terms
7 # This software may be used and distributed according to the terms
8 # of the GNU General Public License, incorporated herein by reference.
8 # of the GNU General Public License, incorporated herein by reference.
9
9
10 import os, sys, shutil, re
10 import difflib
11 import errno
12 import optparse
13 import os
14 import popen2
15 import re
16 import shutil
17 import signal
18 import sys
11 import tempfile
19 import tempfile
12 import difflib
20 import time
13 import popen2
14 from optparse import OptionParser
15
21
16 required_tools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"]
22 required_tools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"]
17
23
18 parser = OptionParser("%prog [options] [tests]")
24 parser = optparse.OptionParser("%prog [options] [tests]")
19 parser.add_option("-v", "--verbose", action="store_true",
25 parser.add_option("-v", "--verbose", action="store_true",
20 help="output verbose messages")
26 help="output verbose messages")
27 parser.add_option("-t", "--timeout", type="int",
28 help="output verbose messages")
21 parser.add_option("-c", "--cover", action="store_true",
29 parser.add_option("-c", "--cover", action="store_true",
22 help="print a test coverage report")
30 help="print a test coverage report")
23 parser.add_option("-s", "--cover_stdlib", action="store_true",
31 parser.add_option("-s", "--cover_stdlib", action="store_true",
24 help="print a test coverage report inc. standard libraries")
32 help="print a test coverage report inc. standard libraries")
25 parser.add_option("-C", "--annotate", action="store_true",
33 parser.add_option("-C", "--annotate", action="store_true",
26 help="output files annotated with coverage")
34 help="output files annotated with coverage")
35 parser.set_defaults(timeout=30)
27 (options, args) = parser.parse_args()
36 (options, args) = parser.parse_args()
28 verbose = options.verbose
37 verbose = options.verbose
29 coverage = options.cover or options.cover_stdlib or options.annotate
38 coverage = options.cover or options.cover_stdlib or options.annotate
@@ -159,6 +168,12 b' def output_coverage():'
159 vlog("# Running: "+cmd)
168 vlog("# Running: "+cmd)
160 os.system(cmd)
169 os.system(cmd)
161
170
171 class Timeout(Exception):
172 pass
173
174 def alarmed(signum, frame):
175 raise Timeout
176
162 def run(cmd):
177 def run(cmd):
163 """Run command in a sub-process, capturing the output (stdout and stderr).
178 """Run command in a sub-process, capturing the output (stdout and stderr).
164 Return the exist code, and output."""
179 Return the exist code, and output."""
@@ -172,9 +187,17 b' def run(cmd):'
172 ret = 0
187 ret = 0
173 else:
188 else:
174 proc = popen2.Popen4(cmd)
189 proc = popen2.Popen4(cmd)
175 proc.tochild.close()
190 try:
176 output = proc.fromchild.read()
191 output = ''
177 ret = proc.wait()
192 proc.tochild.close()
193 output = proc.fromchild.read()
194 ret = proc.wait()
195 except Timeout:
196 vlog('# Process %d timed out - killing it' % proc.pid)
197 os.kill(proc.pid, signal.SIGTERM)
198 ret = proc.wait()
199 if ret == 0:
200 ret = signal.SIGTERM << 8
178 return ret, splitnewlines(output)
201 return ret, splitnewlines(output)
179
202
180 def run_one(test):
203 def run_one(test):
@@ -204,10 +227,16 b' def run_one(test):'
204 if os.name == 'nt' and test.endswith(".bat"):
227 if os.name == 'nt' and test.endswith(".bat"):
205 cmd = 'cmd /c call "%s"' % (os.path.join(TESTDIR, test))
228 cmd = 'cmd /c call "%s"' % (os.path.join(TESTDIR, test))
206
229
230 if options.timeout > 0:
231 signal.alarm(options.timeout)
232
207 vlog("# Running", cmd)
233 vlog("# Running", cmd)
208 ret, out = run(cmd)
234 ret, out = run(cmd)
209 vlog("# Ret was:", ret)
235 vlog("# Ret was:", ret)
210
236
237 if options.timeout > 0:
238 signal.alarm(0)
239
211 diffret = 0
240 diffret = 0
212 # If reference output file exists, check test output against it
241 # If reference output file exists, check test output against it
213 if os.path.exists(ref):
242 if os.path.exists(ref):
@@ -231,6 +260,30 b' def run_one(test):'
231 f.write(line)
260 f.write(line)
232 f.close()
261 f.close()
233
262
263 # Kill off any leftover daemon processes
264 try:
265 fp = file(DAEMON_PIDS)
266 for line in fp:
267 try:
268 pid = int(line)
269 except ValueError:
270 continue
271 try:
272 os.kill(pid, 0)
273 vlog('# Killing daemon process %d' % pid)
274 os.kill(pid, signal.SIGTERM)
275 time.sleep(0.25)
276 os.kill(pid, 0)
277 vlog('# Daemon process %d is stuck - really killing it' % pid)
278 os.kill(pid, signal.SIGKILL)
279 except OSError, err:
280 if err.errno != errno.ESRCH:
281 raise
282 fp.close()
283 os.unlink(DAEMON_PIDS)
284 except IOError:
285 pass
286
234 os.chdir(TESTDIR)
287 os.chdir(TESTDIR)
235 shutil.rmtree(tmpd, True)
288 shutil.rmtree(tmpd, True)
236 return ret == 0
289 return ret == 0
@@ -252,6 +305,8 b' os.environ["HGRCPATH"] = ""'
252
305
253 TESTDIR = os.environ["TESTDIR"] = os.getcwd()
306 TESTDIR = os.environ["TESTDIR"] = os.getcwd()
254 HGTMP = os.environ["HGTMP"] = tempfile.mkdtemp("", "hgtests.")
307 HGTMP = os.environ["HGTMP"] = tempfile.mkdtemp("", "hgtests.")
308 DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
309
255 vlog("# Using TESTDIR", TESTDIR)
310 vlog("# Using TESTDIR", TESTDIR)
256 vlog("# Using HGTMP", HGTMP)
311 vlog("# Using HGTMP", HGTMP)
257
312
@@ -264,6 +319,15 b' try:'
264 try:
319 try:
265 install_hg()
320 install_hg()
266
321
322 if options.timeout > 0:
323 try:
324 signal.signal(signal.SIGALRM, alarmed)
325 vlog('# Running tests with %d-second timeout' %
326 options.timeout)
327 except AttributeError:
328 print 'WARNING: cannot run tests with timeouts'
329 options.timeout = 0
330
267 tests = 0
331 tests = 0
268 failed = 0
332 failed = 0
269
333
@@ -17,6 +17,7 b' echo "[web]" >> .hg/hgrc'
17 echo "name = test-archive" >> .hg/hgrc
17 echo "name = test-archive" >> .hg/hgrc
18 echo "allow_archive = gz bz2, zip" >> .hg/hgrc
18 echo "allow_archive = gz bz2, zip" >> .hg/hgrc
19 hg serve -p 20059 -d --pid-file=hg.pid
19 hg serve -p 20059 -d --pid-file=hg.pid
20 cat hg.pid >> $DAEMON_PIDS
20
21
21 TIP=`hg id -v | cut -f1 -d' '`
22 TIP=`hg id -v | cut -f1 -d' '`
22 QTIP=`hg id -q`
23 QTIP=`hg id -q`
@@ -32,9 +33,6 b' http_proxy= python getarchive.py "$TIP" '
32 http_proxy= python getarchive.py "$TIP" zip > archive.zip
33 http_proxy= python getarchive.py "$TIP" zip > archive.zip
33 unzip -t archive.zip | sed "s/$QTIP/TIP/"
34 unzip -t archive.zip | sed "s/$QTIP/TIP/"
34
35
35 kill `cat hg.pid`
36 sleep 1 # wait for server to scream and die
37
38 hg archive -t tar test.tar
36 hg archive -t tar test.tar
39 tar tf test.tar
37 tar tf test.tar
40
38
@@ -5,10 +5,12 b' cd a'
5 echo a > a
5 echo a > a
6 hg ci -Ama -d '1123456789 0'
6 hg ci -Ama -d '1123456789 0'
7 hg serve -p 20059 -d --pid-file=hg.pid
7 hg serve -p 20059 -d --pid-file=hg.pid
8 cat hg.pid >> $DAEMON_PIDS
8
9
9 cd ..
10 cd ..
10 ("$TESTDIR/tinyproxy.py" 20060 localhost >/dev/null 2>&1 </dev/null &
11 ("$TESTDIR/tinyproxy.py" 20060 localhost >proxy.log 2>&1 </dev/null &
11 echo $! > proxy.pid)
12 echo $! > proxy.pid)
13 cat proxy.pid >> $DAEMON_PIDS
12 sleep 2
14 sleep 2
13
15
14 echo %% url for proxy
16 echo %% url for proxy
@@ -26,5 +28,4 b' http_proxy=http://user:passwd@localhost:'
26 echo %% bad host:port for proxy
28 echo %% bad host:port for proxy
27 http_proxy=localhost:20061 hg clone --config http_proxy.always=True http://localhost:20059/ f
29 http_proxy=localhost:20061 hg clone --config http_proxy.always=True http://localhost:20059/ f
28
30
29 kill `cat proxy.pid a/hg.pid`
30 exit 0
31 exit 0
@@ -9,6 +9,7 b' for i in 0 1 2 3 4 5 6 7 8; do'
9 done
9 done
10 hg verify
10 hg verify
11 hg serve -p 20059 -d --pid-file=hg.pid
11 hg serve -p 20059 -d --pid-file=hg.pid
12 cat hg.pid >> $DAEMON_PIDS
12 cd ..
13 cd ..
13
14
14 hg init new
15 hg init new
@@ -45,5 +46,3 b' cd ..'
45 hg -R test-dev outgoing test
46 hg -R test-dev outgoing test
46 http_proxy= hg -R test-dev outgoing http://localhost:20059/
47 http_proxy= hg -R test-dev outgoing http://localhost:20059/
47 http_proxy= hg -R test-dev outgoing -r 11 http://localhost:20059/
48 http_proxy= hg -R test-dev outgoing -r 11 http://localhost:20059/
48
49 kill `cat test/hg.pid`
@@ -8,6 +8,7 b' hg addremove'
8 hg commit -m 1
8 hg commit -m 1
9 hg verify
9 hg verify
10 hg serve -p 20059 -d --pid-file=hg.pid
10 hg serve -p 20059 -d --pid-file=hg.pid
11 cat hg.pid >> $DAEMON_PIDS
11 cd ..
12 cd ..
12
13
13 http_proxy= hg clone http://localhost:20059/ copy
14 http_proxy= hg clone http://localhost:20059/ copy
@@ -17,5 +18,3 b' hg co'
17 cat foo
18 cat foo
18 hg manifest
19 hg manifest
19 hg pull
20 hg pull
20
21 kill `cat ../test/hg.pid`
@@ -15,6 +15,7 b' cd ../test'
15
15
16 echo % expect ssl error
16 echo % expect ssl error
17 hg serve -p 20059 -d --pid-file=hg.pid
17 hg serve -p 20059 -d --pid-file=hg.pid
18 cat hg.pid >> $DAEMON_PIDS
18 hg --cwd ../test2 push http://localhost:20059/
19 hg --cwd ../test2 push http://localhost:20059/
19 kill `cat hg.pid`
20 kill `cat hg.pid`
20
21
@@ -22,18 +23,21 b' echo % expect authorization error'
22 echo '[web]' > .hg/hgrc
23 echo '[web]' > .hg/hgrc
23 echo 'push_ssl = false' >> .hg/hgrc
24 echo 'push_ssl = false' >> .hg/hgrc
24 hg serve -p 20059 -d --pid-file=hg.pid
25 hg serve -p 20059 -d --pid-file=hg.pid
26 cat hg.pid >> $DAEMON_PIDS
25 hg --cwd ../test2 push http://localhost:20059/
27 hg --cwd ../test2 push http://localhost:20059/
26 kill `cat hg.pid`
28 kill `cat hg.pid`
27
29
28 echo % expect authorization error: must have authorized user
30 echo % expect authorization error: must have authorized user
29 echo 'allow_push = unperson' >> .hg/hgrc
31 echo 'allow_push = unperson' >> .hg/hgrc
30 hg serve -p 20059 -d --pid-file=hg.pid
32 hg serve -p 20059 -d --pid-file=hg.pid
33 cat hg.pid >> $DAEMON_PIDS
31 hg --cwd ../test2 push http://localhost:20059/
34 hg --cwd ../test2 push http://localhost:20059/
32 kill `cat hg.pid`
35 kill `cat hg.pid`
33
36
34 echo % expect success
37 echo % expect success
35 echo 'allow_push = *' >> .hg/hgrc
38 echo 'allow_push = *' >> .hg/hgrc
36 hg serve -p 20059 -d --pid-file=hg.pid
39 hg serve -p 20059 -d --pid-file=hg.pid
40 cat hg.pid >> $DAEMON_PIDS
37 hg --cwd ../test2 push http://localhost:20059/
41 hg --cwd ../test2 push http://localhost:20059/
38 kill `cat hg.pid`
42 kill `cat hg.pid`
39 hg rollback
43 hg rollback
@@ -41,11 +45,13 b' hg rollback'
41 echo % expect authorization error: all users denied
45 echo % expect authorization error: all users denied
42 echo 'deny_push = *' >> .hg/hgrc
46 echo 'deny_push = *' >> .hg/hgrc
43 hg serve -p 20059 -d --pid-file=hg.pid
47 hg serve -p 20059 -d --pid-file=hg.pid
48 cat hg.pid >> $DAEMON_PIDS
44 hg --cwd ../test2 push http://localhost:20059/
49 hg --cwd ../test2 push http://localhost:20059/
45 kill `cat hg.pid`
50 kill `cat hg.pid`
46
51
47 echo % expect authorization error: some users denied, users must be authenticated
52 echo % expect authorization error: some users denied, users must be authenticated
48 echo 'deny_push = unperson' >> .hg/hgrc
53 echo 'deny_push = unperson' >> .hg/hgrc
49 hg serve -p 20059 -d --pid-file=hg.pid
54 hg serve -p 20059 -d --pid-file=hg.pid
55 cat hg.pid >> $DAEMON_PIDS
50 hg --cwd ../test2 push http://localhost:20059/
56 hg --cwd ../test2 push http://localhost:20059/
51 kill `cat hg.pid`
57 kill `cat hg.pid`
@@ -11,6 +11,7 b' ENDSOME'
11 hg add sometext.txt
11 hg add sometext.txt
12 hg commit -d "1 0" -m "Just some text"
12 hg commit -d "1 0" -m "Just some text"
13 hg serve -p 20059 -A access.log -E error.log -d --pid-file=hg.pid
13 hg serve -p 20059 -A access.log -E error.log -d --pid-file=hg.pid
14 cat hg.pid >> $DAEMON_PIDS
14 ("$TESTDIR/get-with-headers.py" localhost:20059 '/?f=f165dc289438;file=sometext.txt;style=raw' content-type content-length content-disposition) >getoutput.txt &
15 ("$TESTDIR/get-with-headers.py" localhost:20059 '/?f=f165dc289438;file=sometext.txt;style=raw' content-type content-length content-disposition) >getoutput.txt &
15
16
16 sleep 5
17 sleep 5
General Comments 0
You need to be logged in to leave comments. Login now