diff tests/tinyproxy.py @ 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 0b21ae0a2366
children 7292a4618f46
line wrap: on
line diff
--- 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