Browse Source

Moved tests to their own subdirectory.

Adding wait for retry on process failure.



git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1220 e5f2f494-b856-4b98-b285-d166d9295462
Shane Kerr 15 years ago
parent
commit
1257b9301f

+ 1 - 1
configure.ac

@@ -171,7 +171,7 @@ AC_OUTPUT([src/bin/cfgmgr/b10-cfgmgr.py
            src/bin/cmdctl/run_b10-cmdctl.sh
            src/bin/cmdctl/unittest/cmdctl_test
            src/bin/bind10/bind10.py
-           src/bin/bind10/bind10_test
+           src/bin/bind10/tests/bind10_test
            src/bin/bind10/run_bind10.sh
            src/bin/bindctl/bindctl
            src/bin/bindctl/unittest/bindctl_test

+ 5 - 0
src/bin/bind10/Makefile.am

@@ -12,3 +12,8 @@ bind10: bind10.py
 	$(SED) -e "s|@@PYTHONPATH@@|@pyexecdir@|" \
 	       -e "s|@@LIBEXECDIR@@|$(pkglibexecdir)|" bind10.py >$@
 	chmod a+x $@
+
+check: test
+
+test: 
+	$(SHELL) tests/bind10_test

+ 42 - 1
src/bin/bind10/bind10.py.in

@@ -2,6 +2,7 @@
 
 import sys; sys.path.append ('@@PYTHONPATH@@')
 import os
+import time
 
 """\
 This file implements the Boss of Bind (BoB, or bob) program.
@@ -50,11 +51,49 @@ import isc.cc
 import isc
 
 # This is the version that gets displayed to the user.
-__version__ = "v20100225"
+__version__ = "v20100308"
 
 # Nothing at all to do with the 1990-12-10 article here:
 # http://www.subgenius.com/subg-digest/v2/0056.html
 
+class RestartSchedule:
+    """
+Keeps state when restarting something (in this case, a process).
+
+When a process dies unexpectedly, we need to restart it. However, if 
+it fails to restart for some reason, then we should not simply keep
+restarting it at high speed.
+
+A more sophisticated algorithm can be developed, but for now we choose
+a simple set of rules:
+
+  * If a process was been running for >=10 seconds, we restart it
+    right away.
+  * If a process was running for <10 seconds, we wait until 10 seconds
+    after it was started."""
+
+    def __init__(self, restart_frequency=10.0):
+        self.restart_frequency = restart_frequency
+        self.run_start_time = None
+        self.run_stop_time = None
+        self.restart_time = None
+    
+    def set_run_start_time(self, when=None):
+        if when is None:
+            when = time.time()
+        self.run_start_time = when
+        self.restart_time = when + self.restart_frequency
+
+    def set_run_stop_time(self, when=None):
+        if when is None:
+            when = time.time()
+        self.run_stop_time = when
+
+    def get_restart_time(self, when=None):
+        if when is None:
+            when = time.time()
+        return max(when, self.restart_time)
+
 class ProcessInfo:
     """Information about a process"""
 
@@ -89,6 +128,8 @@ class ProcessInfo:
         self.env = env
         self.dev_null_stdout = dev_null_stdout
         self._spawn()
+        self.last_spawn_time = time.time()
+#        self.respawn
 
     def respawn(self):
         self._spawn()

+ 2 - 2
src/bin/bind10/bind10_test.in

@@ -8,9 +8,9 @@ BIND10_PATH=@abs_top_srcdir@/src/bin/bind10
 PATH=@abs_top_srcdir@/src/bin/msgq:@abs_top_srcdir@/src/bin/auth:@abs_top_srcdir@/src/bin/bind-cfgd:$PATH
 export PATH
 
-PYTHONPATH=@abs_top_srcdir@/src/lib/python
+PYTHONPATH=@abs_top_srcdir@/src/lib/python:@abs_top_srcdir@/src/bin/bind10
 export PYTHONPATH
 
-cd ${BIND10_PATH}
+cd ${BIND10_PATH}/tests
 exec ${PYTHON_EXEC} -O bind10_test.py $*
 

src/bin/bind10/bind10_test.py → src/bin/bind10/tests/bind10_test.py