[PATCH 3 of 3] killdaemons: read pids from file arguments if any

Patrick Mezard patrick at mezard.eu
Sun Aug 19 14:22:41 CDT 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1345403716 -7200
# Node ID f474bf5159f481399e55485769d774183d7cf120
# Parent  59dcbbaf61aee7f9b534454820ea00e1bf204c74
killdaemons: read pids from file arguments if any

With no arguments, fallback to the previous behaviour of reading from
$DAEMON_PIDS.

On Windows, MinGW kill implementation does not seem to use system
process identifiers, and systematically fails when called in tests.
killdaemons.py could be a suitable replacement.

test-http-branchmap.t is updated to be run by Windows test suite. The:

  listening at http://*:$HGPORT1/

line does not appear on Windows because the detached process can no
longer write on its parent streams. Grepping hg serve stdout directly
causes the parent process to never return and hang the test. This is a
bug, but I have no simple solution and prefer to pay this small price
and enable hg serve tests on Windows.

If this change is accepted, the plan is to:
- Check test-http-branchmap.t does not fail/hang on the buildbot
- Convert all kill utility calls to killdaemons.py calls
- Add a rule in check-code.py to forbid kill calls
- Possibly drop the 'server' rule from hghave.

diff --git a/tests/killdaemons.py b/tests/killdaemons.py
--- a/tests/killdaemons.py
+++ b/tests/killdaemons.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import os, time, errno, signal
+import os, sys, time, errno, signal
 
 if os.name =='nt':
     import ctypes
@@ -49,5 +49,9 @@
         pass
 
 if __name__ == '__main__':
-    killdaemons(os.environ['DAEMON_PIDS'])
+    paths = sys.argv[1:]
+    if not paths:
+        paths = [os.environ['DAEMON_PIDS']]
+    for path in paths:
+        killdaemons(path)
 
diff --git a/tests/test-http-branchmap.t b/tests/test-http-branchmap.t
--- a/tests/test-http-branchmap.t
+++ b/tests/test-http-branchmap.t
@@ -1,7 +1,8 @@
-  $ "$TESTDIR/hghave" serve || exit 80
-
   $ hgserve() {
-  >     hg serve -a localhost -p $HGPORT1 -d --pid-file=hg.pid -E errors.log -v $@
+  >     hg serve -a localhost -p $HGPORT1 -d --pid-file=hg.pid \
+  >       -E errors.log -v $@ > startup.log
+  >     # Grepping hg serve stdout would hang on Windows
+  >     grep -v 'listening at' startup.log
   >     cat hg.pid >> "$DAEMON_PIDS"
   > }
   $ hg init a
@@ -12,7 +13,6 @@
   $ hg -R a ci -Am foo
   adding foo
   $ hgserve -R a --config web.push_ssl=False --config web.allow_push=* --encoding latin1
-  listening at http://*:$HGPORT1/ (bound to 127.0.0.1:$HGPORT1) (glob)
   $ hg --encoding utf-8 clone http://localhost:$HGPORT1 b
   requesting all changes
   adding changesets
@@ -52,7 +52,7 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     foo
   
-  $ kill `cat hg.pid`
+  $ "$TESTDIR/killdaemons.py" hg.pid
 
 verify 7e7d56fe4833 (encoding fallback in branchmap to maintain compatibility with 1.3.x)
 


More information about the Mercurial-devel mailing list