Commit dcdb807c authored by tansell's avatar tansell Committed by Commit bot

webkitpy: Check xvfb with xdpyinfo after starting.

This makes sure that xvfb actually started correctly and you can connect
to it. We don't use -display argument as we want to make sure the
environment is correct.

BUG=713597

Review-Url: https://codereview.chromium.org/2837773002
Cr-Commit-Position: refs/heads/master@{#467253}
parent bd0fcfc5
......@@ -48,6 +48,8 @@ class LinuxPort(base.Port):
BUILD_REQUIREMENTS_URL = 'https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md'
XVFB_START_TIMEOUT = 5.0 # Wait up to 5 seconds for Xvfb to start.
@classmethod
def determine_full_port_name(cls, host, options, port_name):
if port_name.endswith('linux'):
......@@ -168,6 +170,19 @@ class LinuxPort(base.Port):
if self._xvfb_process.poll() is not None:
_log.warn('Failed to start Xvfb on display "%s."', display)
start_time = self.host.time()
while self.host.time() - start_time < self.XVFB_START_TIMEOUT:
# We don't explicitly set the display, as we want to check the
# environment value.
exit_code = self.host.executive.run_command(
['xdpyinfo'], return_exit_code=True)
if exit_code == 0:
_log.info('Successfully started Xvfb with display "%s".', display)
return
_log.warn('xdpyinfo check failed with exit code %s while starting Xvfb on "%s".', exit_code, display)
self.host.sleep(0.1)
_log.fatal('Failed to start Xvfb on display "%s" (xdpyinfo check failed).', display)
def _find_display(self):
"""Tries to find a free X display, looping if necessary."""
# The "xvfb-run" command uses :99 by default.
......
......@@ -116,22 +116,37 @@ class LinuxPortTest(port_testcase.PortTestCase):
self.assertFalse(port.host.filesystem.exists(temp_home_dir))
def test_setup_test_run_starts_xvfb(self):
def run_command_fake(args):
if args[0] == 'xdpyinfo':
if '-display' in args:
return 1
return 0
port = self.make_port()
port.host.executive = MockExecutive(exit_code=1)
port.host.executive = MockExecutive(
run_command_fn=run_command_fake)
port.setup_test_run()
self.assertEqual(
port.host.executive.calls,
[
['xdpyinfo', '-display', ':99'],
['Xvfb', ':99', '-screen', '0', '1280x800x24', '-ac', '-dpi', '96'],
['xdpyinfo'],
])
env = port.setup_environ_for_server()
self.assertEqual(env['DISPLAY'], ':99')
def test_setup_test_runs_finds_free_display(self):
def run_command_fake(args):
if args[0] == 'xdpyinfo':
if '-display' in args:
if ':102' in args:
return 1
return 0
port = self.make_port()
port.host.executive = MockExecutive(
run_command_fn=lambda args: 1 if ':102' in args else 0)
run_command_fn=run_command_fake)
port.setup_test_run()
self.assertEqual(
port.host.executive.calls,
......@@ -141,6 +156,56 @@ class LinuxPortTest(port_testcase.PortTestCase):
['xdpyinfo', '-display', ':101'],
['xdpyinfo', '-display', ':102'],
['Xvfb', ':102', '-screen', '0', '1280x800x24', '-ac', '-dpi', '96'],
['xdpyinfo'],
])
env = port.setup_environ_for_server()
self.assertEqual(env['DISPLAY'], ':102')
def test_setup_test_runs_multiple_checks_when_slow_to_start(self):
count = [0]
def run_command_fake(args):
if args[0] == 'xdpyinfo':
if '-display' in args:
return 1
if count[0] < 3:
count[0] += 1
return 1
return 0
port = self.make_port()
port.host.executive = MockExecutive(
run_command_fn=run_command_fake)
port.setup_test_run()
self.assertEqual(
port.host.executive.calls,
[
['xdpyinfo', '-display', ':99'],
['Xvfb', ':99', '-screen', '0', '1280x800x24', '-ac', '-dpi', '96'],
['xdpyinfo'],
['xdpyinfo'],
['xdpyinfo'],
['xdpyinfo'],
])
env = port.setup_environ_for_server()
self.assertEqual(env['DISPLAY'], ':99')
def test_setup_test_runs_eventually_failes_on_failure(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)
port.host.executive = MockExecutive(
run_command_fn=run_command_fake)
port.setup_test_run()
self.assertEqual(
port.host.executive.calls,
[
['xdpyinfo', '-display', ':99'],
['Xvfb', ':99', '-screen', '0', '1280x800x24', '-ac', '-dpi', '96'],
] + [['xdpyinfo']] * 51)
env = port.setup_environ_for_server()
self.assertEqual(env['DISPLAY'], ':99')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment