diff --git a/tests/killdaemons.py b/tests/killdaemons.py new file mode 100644 --- /dev/null +++ b/tests/killdaemons.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +import os, sys, time, errno, signal + +# Kill off any leftover daemon processes +try: + fp = file(os.environ['DAEMON_PIDS']) + for line in fp: + try: + pid = int(line) + except ValueError: + continue + try: + os.kill(pid, 0) + os.kill(pid, signal.SIGTERM) + for i in range(10): + time.sleep(0.05) + os.kill(pid, 0) + os.kill(pid, signal.SIGKILL) + except OSError, err: + if err.errno != errno.ESRCH: + raise + fp.close() +except IOError: + pass diff --git a/tests/test-archive b/tests/test-archive --- a/tests/test-archive +++ b/tests/test-archive @@ -24,7 +24,7 @@ test_archtype() { echo % $3 and $4 disallowed should both give 403 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$3" | head -n 1 "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/archive/tip.$4" | head -n 1 - kill `cat hg.pid` + "$TESTDIR/killdaemons.py" cat errors.log cp .hg/hgrc-base .hg/hgrc } @@ -63,6 +63,8 @@ http_proxy= python getarchive.py "$TIP" http_proxy= python getarchive.py "$TIP" zip > archive.zip unzip -t archive.zip | sed "s/$QTIP/TIP/" +"$TESTDIR/killdaemons.py" + hg archive -t tar test.tar tar tf test.tar diff --git a/tests/test-fetch b/tests/test-fetch --- a/tests/test-fetch +++ b/tests/test-fetch @@ -37,6 +37,7 @@ echo % should merge c into a hg --cwd c fetch -d '4 0' -m 'automated merge' ../a ls c +netstat -tnap 2>/dev/null | grep $HGPORT | grep LISTEN hg --cwd a serve -a localhost -p $HGPORT -d --pid-file=hg.pid cat a/hg.pid >> "$DAEMON_PIDS" @@ -169,4 +170,6 @@ echo '% parent should be 0 (fetch did no hg -R n2 parents --template '{rev}\n' rm -fr n1 n2 +"$TESTDIR/killdaemons.py" + true