[gnome-settings-daemon/wip/benzea/ci] tests: Fix race condition checking for Xvfb startup
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/benzea/ci] tests: Fix race condition checking for Xvfb startup
- Date: Thu, 15 Mar 2018 22:06:33 +0000 (UTC)
commit 006b4fba4abfb388d480ad84ae5e56b7ca595bc6
Author: Benjamin Berg <bberg redhat com>
Date: Thu Mar 15 22:33:09 2018 +0100
tests: Fix race condition checking for Xvfb startup
When two Xvfb processes are started at the same time, then the xprop
check on whether the startup was successful might succeed on the wrong
instance.
Fix this by simply waiting a long time for the Xvfb server to start up.
There are probably better solutions to this, but adding a fixed delay
doesn't slow down the testsuite much overall.
tests/gsdtestcase.py | 42 ++++++++++++++++++++----------------------
1 file changed, 20 insertions(+), 22 deletions(-)
---
diff --git a/tests/gsdtestcase.py b/tests/gsdtestcase.py
index cc94006d..a8fc4c0e 100644
--- a/tests/gsdtestcase.py
+++ b/tests/gsdtestcase.py
@@ -203,30 +203,28 @@ class GSDTestCase(dbusmock.DBusTestCase):
stdout=xorg_log_write, stderr=subprocess.STDOUT)
os.environ['DISPLAY'] = ':%d' % display_num
- # wait until the server is ready
- timeout = 50
- while timeout > 0:
- time.sleep(0.1)
- timeout -= 1
- if klass.xorg.poll():
- # ended prematurely
- try:
- log = open(xorg_log).read()
- except IOError:
- sys.stderr.write('Could not read server log after Xvfb died!\n--------\n')
- return -1
-
- if b'Server is already active for display' in log:
- sys.stderr.write('Server already active for display :%d.\n--------\n' % display_num)
- # No use in keeping that log
- os.unlink(xorg_log)
- return 0
-
+ # Note that we used to loop here, but that gives us a race condition
+ # where xprop would connect to an Xvfb instance spawned by another
+ # process.
+ # So for now, just sleep for a few seconds instead
+ time.sleep(5)
+ if klass.xorg.poll():
+ # ended prematurely
+ try:
+ log = open(xorg_log).read()
+ except IOError:
+ sys.stderr.write('Could not read server log after Xvfb died!\n--------\n')
return -1
- if subprocess.call(['xprop', '-root'], stdout=subprocess.PIPE,
+
+ if b'Server is already active for display' in log:
+ sys.stderr.write('Server already active for display :%d.\n--------\n' % display_num)
+ # No use in keeping that log
+ os.unlink(xorg_log)
+ return 0
+
+ return -1
+ if not subprocess.call(['xprop', '-root'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE) == 0:
- break
- if timeout <= 0:
sys.stderr.write('Timeout waiting for Xvfb to start.\n--------\n')
# Ensure xorg process is really dead
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]