Exemplo n.º 1
0
    def test_setup_test_runs_terminates_if_xvfb_proc_fails(self):
        def run_command_fake(args):
            if args[0] == 'xdpyinfo':
                return 1
            return 0

        host = MockSystemHost(os_name=self.os_name, os_version=self.os_version)
        port = self.make_port(host=host)
        # Xvfb is started via Executive.popen, which returns an object for the
        # process. Here we set up a fake process object that acts as if it has
        # exited with return code 1 immediately.
        proc = MockProcess(stdout='', stderr='', returncode=3)
        port.host.executive = MockExecutive(run_command_fn=run_command_fake,
                                            proc=proc)
        self.set_logging_level(logging.DEBUG)

        self.assertEqual(port.setup_test_run(), SYS_DEPS_EXIT_STATUS)
        self.assertEqual(port.host.executive.calls, [[
            'xdpyinfo', '-display', ':99'
        ], ['Xvfb', ':99', '-screen', '0', '1280x800x24', '-ac', '-dpi', '96']
                                                     ])
        self.assertLog([
            'DEBUG: Starting Xvfb with display ":99".\n',
            'CRITICAL: Failed to start Xvfb on display ":99" (xvfb retcode: 3).\n'
        ])
    def test_start_with_unkillable_zombie_process(self):
        # Allow asserting about debug logs.
        self.set_logging_level(logging.DEBUG)

        self.host.filesystem.write_text_file('/log_file_dir/access_log', 'foo')
        self.host.filesystem.write_text_file('/log_file_dir/error_log', 'foo')
        self.host.filesystem.write_text_file('/tmp/pidfile', '7')

        server = WPTServe(self.port, '/log_file_dir')
        server._pid_file = '/tmp/pidfile'
        server._spawn_process = lambda: 4
        server._process = MockProcess()
        server._is_server_running_on_all_ports = lambda: True

        # Simulate a process that never gets killed.
        self.host.executive.check_running_pid = lambda _: True

        server.start()
        self.assertEqual(server._pid, 4)
        self.assertIsNone(self.host.filesystem.files[server._pid_file])

        # In this case, we'll try to kill the process repeatedly,
        # then give up and just try to start a new process anyway.
        logs = self.logMessages()
        self.assertEqual(len(logs), 43)
        self.assertEqual(logs[:2], [
            'DEBUG: stale wptserve pid file, pid 7\n',
            'DEBUG: pid 7 is running, killing it\n'
        ])
        self.assertEqual(logs[-2:], [
            'DEBUG: all ports are available\n',
            'DEBUG: wptserve successfully started (pid = 4)\n'
        ])