changeset 16300:74e114ac6ec1 stable

tests: fix startup/shutdown races in test-https tinyproxy now writes its own pid when it's ready to accept connections
author Matt Mackall <mpm@selenic.com>
date Wed, 28 Mar 2012 19:23:25 -0500
parents 853ffcafecfa
children de4cb5c42007
files tests/test-https.t tests/tinyproxy.py
diffstat 2 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-https.t	Wed Mar 28 12:02:38 2012 -0500
+++ b/tests/test-https.t	Wed Mar 28 19:23:25 2012 -0500
@@ -233,15 +233,13 @@
   $ hg -R copy-pull id https://127.0.0.1:$HGPORT/
   5fed3813f7f5
 
+  $ while kill `cat hg1.pid` 2>/dev/null; do true; done
+
 Prepare for connecting through proxy
 
-  $ kill `cat hg1.pid`
-  $ sleep 1
-
-  $ ("$TESTDIR/tinyproxy.py" $HGPORT1 localhost >proxy.log 2>&1 </dev/null &
-  $ echo $! > proxy.pid)
+  $ "$TESTDIR/tinyproxy.py" $HGPORT1 localhost >proxy.log </dev/null 2>&1 &
+  $ while [ ! -f proxy.pid ]; do true; done
   $ cat proxy.pid >> $DAEMON_PIDS
-  $ sleep 2
 
   $ echo "[http_proxy]" >> copy-pull/.hg/hgrc
   $ echo "always=True" >> copy-pull/.hg/hgrc
--- a/tests/tinyproxy.py	Wed Mar 28 12:02:38 2012 -0500
+++ b/tests/tinyproxy.py	Wed Mar 28 19:23:25 2012 -0500
@@ -12,7 +12,7 @@
 
 __version__ = "0.2.1"
 
-import BaseHTTPServer, select, socket, SocketServer, urlparse
+import BaseHTTPServer, select, socket, SocketServer, urlparse, os
 
 class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
     __base = BaseHTTPServer.BaseHTTPRequestHandler
@@ -122,7 +122,12 @@
     do_DELETE = do_GET
 
 class ThreadingHTTPServer (SocketServer.ThreadingMixIn,
-                           BaseHTTPServer.HTTPServer): pass
+                           BaseHTTPServer.HTTPServer):
+    def __init__(self, *args, **kwargs):
+        BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs)
+        a = open("proxy.pid", "w")
+        a.write(str(os.getpid()) + "\n")
+        a.close()
 
 if __name__ == '__main__':
     from sys import argv