Commits

Matt Mackall committed 58fd3c7

tests: add killdaemons helper script

Comments (0)

Files changed (3)

tests/killdaemons.py

+#!/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

tests/test-archive

     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
 }
 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
 
 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"
 
 hg -R n2 parents --template '{rev}\n'
 rm -fr n1 n2
 
+"$TESTDIR/killdaemons.py"
+
 true