505
505
ct::CompizXorgSystemTest::SetUp ()
507
xorg::testing::Test::SetUp ();
507
const unsigned int MAX_CONNECTION_ATTEMPTS = 10;
508
const unsigned int USEC_TO_MSEC = 1000;
509
const unsigned int SLEEP_TIME = 50 * USEC_TO_MSEC;
511
unsigned int connectionAttemptsRemaining = MAX_CONNECTION_ATTEMPTS;
513
/* Work around an inherent race condition in XOpenDisplay
515
* All xorg::testing::Test::SetUp does is call XOpenDisplay
516
* and assign a display string, the former before the latter.
517
* The current X Error handler will throw an exception if
518
* an X error occurrs.
520
* Unfortunately there's an inherent race condition in spawning
521
* a new server and using XOpenDisplay to connect to it - we
522
* simply don't know when the new server will be ready, and even
523
* watching its socket with inotify will be racey too. The only
524
* solution would be a handshake process where we pass the server
525
* a socket or pipe and it writes to it indicating that it is ready
526
* to accept connections. There isn't such a thing. As such, we need
527
* to work around that by simply re-trying our connection to the server
528
* once every 50ms or so, and we're trying about 10 times before giving up
529
* and assuming there is a problem with the server.
531
while (connectionAttemptsRemaining--)
535
xorg::testing::Test::SetUp ();
538
catch (std::runtime_error &exception)
544
if (!connectionAttemptsRemaining)
546
throw std::runtime_error ("Failed to connect to X Server. "\
547
"Check the logs by setting "\
548
"XORG_GTEST_CHILD_STDOUT=1 to see if "\
549
"there are any startup errors. Otherwise "\
550
"if you suspect the server is running "\
551
"particularly slowly, try bumping up the "\
552
"maximum number of connection attempts in "\
553
"compiz-xorg-gtest.cpp");