Commit af557c81 authored by Rafael Monnerat's avatar Rafael Monnerat

Automatically find some available display to use with Xvfb.

Check the lock files, and launch the xvfb with some available display.
parent 7542aa0b
...@@ -67,14 +67,27 @@ class TimeoutError(Exception): ...@@ -67,14 +67,27 @@ class TimeoutError(Exception):
pass pass
class Xvfb: class Xvfb:
def __init__(self, fbdir, display): def __init__(self, fbdir):
self.display = display self.display_list = [":%s" % i for i in range(123, 144)]
self.display = None
self.fbdir = fbdir self.fbdir = fbdir
self.pid = None self.pid = None
def _runCommand(self, display):
command = ['Xvfb', '-fbdir' , self.fbdir, display]
self.process = Popen(" ".join(command),
stdout=PIPE,
stderr=PIPE,
shell=True,
close_fds=True)
def run(self): def run(self):
self.pid = os.spawnlp(os.P_NOWAIT, 'Xvfb', 'Xvfb', for display_try in self.display_list:
'-fbdir' , self.fbdir, self.display) lock_filepath = '/tmp/.X%s-lock' % display_try.replace(":", "")
if not os.path.exists(lock_filepath):
self._runCommand(display_try)
self.display = display_try
break
display = os.environ.get('DISPLAY') display = os.environ.get('DISPLAY')
if display: if display:
...@@ -83,13 +96,18 @@ class Xvfb: ...@@ -83,13 +96,18 @@ class Xvfb:
(displayname, protocolname, hexkey) = auth.split() (displayname, protocolname, hexkey) = auth.split()
Popen(['xauth', 'add', 'localhost/unix:%s' % display, protocolname, hexkey]) Popen(['xauth', 'add', 'localhost/unix:%s' % display, protocolname, hexkey])
print 'Xvfb : %d' % self.pid print 'Xvfb : %d' % self.process.pid
print 'Take screenshots using xwud -in %s/Xvfb_screen0' % self.fbdir print 'Take screenshots using xwud -in %s/Xvfb_screen0' % self.fbdir
def quit(self): def quit(self):
if self.pid: if hasattr(self, 'process'):
process_pid = self.process.pid
try:
self.process.terminate()
finally:
if process_pid:
print "Stopping Xvfb on pid: %s" % self.pid print "Stopping Xvfb on pid: %s" % self.pid
os.kill(self.pid, signal.SIGTERM) os.kill(process_pid, signal.SIGTERM)
class Browser: class Browser:
...@@ -234,7 +252,6 @@ class FunctionalTestRunner: ...@@ -234,7 +252,6 @@ class FunctionalTestRunner:
self.user = 'ERP5TypeTestCase' self.user = 'ERP5TypeTestCase'
self.password = '' self.password = ''
self.run_only = run_only self.run_only = run_only
self.xvfb_display = ':123'
profile_dir = os.path.join(self.instance_home, 'profile') profile_dir = os.path.join(self.instance_home, 'profile')
self.portal = portal self.portal = portal
if use_phanthom: if use_phanthom:
...@@ -251,11 +268,10 @@ class FunctionalTestRunner: ...@@ -251,11 +268,10 @@ class FunctionalTestRunner:
self.portal.portal_url(), self.user, self.password) self.portal.portal_url(), self.user, self.password)
def test(self, debug=0): def test(self, debug=0):
xvfb = Xvfb(self.instance_home, None) xvfb = Xvfb(self.instance_home)
try: try:
start = time.time() start = time.time()
if not debug and self.browser.use_xvfb: if not debug and self.browser.use_xvfb:
xvfb.display = self.xvfb_display
xvfb.run() xvfb.run()
self.browser.run(self._getTestURL() , xvfb.display) self.browser.run(self._getTestURL() , xvfb.display)
while self.getStatus() is None: while self.getStatus() is None:
...@@ -291,7 +307,6 @@ class FunctionalTestRunner: ...@@ -291,7 +307,6 @@ class FunctionalTestRunner:
return detail, int(sucess_amount), int(failure_amount), error_title_list return detail, int(sucess_amount), int(failure_amount), error_title_list
class ERP5TypeFunctionalTestCase(ERP5TypeTestCase): class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
run_only = "" run_only = ""
foreground = 0 foreground = 0
......
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