def startService(cls):
     """Start the webservice."""
     googletestservice.kill_running_process()
     cls.service = googletestservice.start_as_process()
     assert cls.service, "The Search service process did not start."
     try:
         googletestservice.wait_for_service()
     except RuntimeError:
         # The service didn't start itself soon enough.  We must
         # make sure to kill any errant processes that may be
         # hanging around.
         cls.stopService()
         raise
 def startService(cls):
     """Start the webservice."""
     googletestservice.kill_running_process()
     cls.service = googletestservice.start_as_process()
     assert cls.service, "The Search service process did not start."
     try:
         googletestservice.wait_for_service()
     except RuntimeError:
         # The service didn't start itself soon enough.  We must
         # make sure to kill any errant processes that may be
         # hanging around.
         cls.stopService()
         raise
    def test_stale_pid_file_cleanup(self):
        """The service should be able to clean up invalid PID files."""
        bogus_pid = 9999999
        self.failIf(process_exists(bogus_pid),
                    "There is already a process with PID '%d'." % bogus_pid)

        # Create a stale/bogus PID file.
        filepath = pidfile_path(googletestservice.service_name)
        pidfile = file(filepath, 'w')
        pidfile.write(str(bogus_pid))
        pidfile.close()

        # The PID clean-up code should silently remove the file and return.
        googletestservice.kill_running_process()
        self.failIf(os.path.exists(filepath),
                    "The PID file '%s' should have been deleted." % filepath)
    def test_stale_pid_file_cleanup(self):
        """The service should be able to clean up invalid PID files."""
        bogus_pid = 9999999
        self.failIf(process_exists(bogus_pid),
                    "There is already a process with PID '%d'." % bogus_pid)

        # Create a stale/bogus PID file.
        filepath = pidfile_path(googletestservice.service_name)
        pidfile = file(filepath, 'w')
        pidfile.write(str(bogus_pid))
        pidfile.close()

        # The PID clean-up code should silently remove the file and return.
        googletestservice.kill_running_process()
        self.failIf(os.path.exists(filepath),
                    "The PID file '%s' should have been deleted." % filepath)