chiark / gitweb /
The initial rescan now blocks any client connections. This means that
[disorder] / tests / dtest.py
index 38c72196f0438a57bc7f5779de2f4f2e53a8ff63..6ae9fd74cdde2f4de9fcff120fca7ee0444d6a2d 100644 (file)
@@ -21,7 +21,7 @@
 
 """Utility module used by tests"""
 
-import os,os.path,subprocess,sys,re
+import os,os.path,subprocess,sys,re,time
 
 def fatal(s):
     """Write an error message and exit"""
@@ -137,12 +137,34 @@ Start the daemon."""
     global daemon, errs
     assert daemon == None
     print " starting daemon"
+    # remove the socket if it exists
+    socket = "%s/socket" % testroot
+    try:
+        os.remove(socket)
+    except:
+        pass
     daemon = subprocess.Popen(["disorderd",
                                "--foreground",
                                "--config", "%s/config" % testroot],
                               stderr=errs)
     disorder._configfile = "%s/config" % testroot
     disorder._userconf = False
+    # Wait for the socket to be created
+    waited = 0
+    while not os.path.exists(socket):
+        rc = daemon.poll()
+        if rc is not None:
+            print "FATAL: daemon failed to start up"
+            sys.exit(1)
+        waited += 1
+        if waited == 1:
+            print "  waiting for socket..."
+        elif waited >= 60:
+            print "FATAL: took too long for socket to appear"
+            sys.exit(1)
+        time.sleep(1)
+    if waited > 0:
+        print "  took about %ds for socket to appear" % waited
 
 def stop_daemon():
     """stop_daemon()
@@ -155,8 +177,11 @@ Stop the daemon if it has not stopped already"""
     if rc == None:
         print " stopping daemon"
         os.kill(daemon.pid, 15)
+        print "  waiting for daemon"
         rc = daemon.wait()
-    print " daemon has stopped"
+        print "  daemon has stopped"
+    else:
+        print "  daemon already stopped"
     daemon = None
 
 def run(module=None, report=True):