Rev 4: Make tests pass. in file:///v/home/vila/.bazaar/plugins/local_test_server/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed May 28 09:27:13 BST 2008


At file:///v/home/vila/.bazaar/plugins/local_test_server/

------------------------------------------------------------
revno: 4
revision-id: v.ladeuil+lp at free.fr-20080528082712-cbye8jpu0qxvz1rf
parent: v.ladeuil+lp at free.fr-20080526194208-9eqqggi0hi421yg0
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: local_test_server
timestamp: Wed 2008-05-28 10:27:12 +0200
message:
  Make tests pass.
  
  * server.py:
  (Apache2._wait_for_pid_death): Another dirty work-around to ensure
  server death.
  
  * commands.py:
  (cmd_lts_start.run, cmd_lts_stop.run): Be friendlier with bzr
  start time, wait to be called before importing.
modified:
  commands.py                    commands.py-20080524160638-76gsirgigzamza15-1
  server.py                      server.py-20080524160639-rqhbexqatjqbwypw-1
-------------- next part --------------
=== modified file 'commands.py'
--- a/commands.py	2008-05-26 19:42:08 +0000
+++ b/commands.py	2008-05-28 08:27:12 +0000
@@ -22,10 +22,6 @@
 import bzrlib.commands
 
 
-from bzrlib.plugins.local_test_server import (
-    server,
-    )
-
 class cmd_lts_start(bzrlib.commands.Command):
     """Start a test server."""
 
@@ -33,6 +29,8 @@
 
     @bzrlib.commands.display_command
     def run(self, name=None):
+        from bzrlib.plugins.local_test_server import server
+
         s = server.get_server(name)
         if server is None:
             raise errors.BzrCommandError('Server %s is unknown')
@@ -48,6 +46,8 @@
 
     @bzrlib.commands.display_command
     def run(self, name=None):
+        from bzrlib.plugins.local_test_server import server
+
         s = server.get_server(name)
         if server is None:
             raise errors.BzrCommandError('Server %s is unknown')

=== modified file 'server.py'
--- a/server.py	2008-05-26 19:42:08 +0000
+++ b/server.py	2008-05-28 08:27:12 +0000
@@ -15,19 +15,17 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """The local test servers interfaces."""
 
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
 import errno
+import os
 import subprocess
 import time
 
 
-from bzrlib import (
-    errors,
-    )
-
-
-from bzrlib.plugins.local_test_server import (
-    config,
-    )
+from bzrlib import errors
+from bzrlib.plugins.local_test_server import config
+""")
 
 
 class Server(object):
@@ -87,13 +85,8 @@
                                '-f', config_filename ])
         self._wait_for_pidfile_to_be_created()
 
-    def stop(self):
-        config_filename = config.get_lts_path('etc/apache2.conf')
-        retcode = subprocess.check_call(['apache2', '-k', 'stop',
-                                         '-f', config_filename ])
-
     def _wait_for_pidfile_to_be_created(self):
-        # I couldn't find a a way/command/parameter to start apache2 to that
+        # I couldn't find a a way/command/parameter to start apache2 so that
         # pidfile file is created when the command returns. Then, if the server
         # fails to start no pidfile is ever created. Damn if you wait, damn if
         # you wait too long ;-)
@@ -108,6 +101,34 @@
             else:
                 time.sleep(delay)
 
+    def stop(self):
+        config_filename = config.get_lts_path('etc/apache2.conf')
+        pid = self.pid
+        # Tell it to stop
+        subprocess.call(['apache2', '-k', 'stop',
+                         '-f', config_filename ])
+        # But of course, it's not enough
+        self._wait_for_pid_death(pid)
+
+    def _wait_for_pid_death(self, pid):
+        # After apache2 is stopped, ensure the corresponding processes are
+        # really dead.
+        started = False
+        delay = 0.001 # 10 ms
+        # total delay to wait in seconds, if you experienced a longer start
+        # time, well, increase.
+        total_delay = 2
+        for i in range(0, int(total_delay * (1  / delay))):
+            try:
+                os.kill(pid, 0)
+            except OSError, e:
+                if e.errno == errno.ESRCH:
+                    # Good, finally it's dead
+                    break
+                else:
+                    raise
+            time.sleep(delay)
+
     def is_running(self):
         return bool(self.pid is not None)
 



More information about the bazaar-commits mailing list