2
votes

I have a job in Jenkins that runs UI tests written in Selenium. The job can run multiple instances of it concurrently. I am running into a problem while trying to use Xvfb (the Xvfb plugin or otherwise).

Using the Xvfb plugin

The configuration is as below. enter image description here The plugin assigns the same display port to 2 concurrent job instances, and then one fails.

From the Xvfb log (note displayfd is 2 and screen is 0 in both cases):

Xvfb starting$ /usr/bin/Xvfb -displayfd 2 -screen 0 1024x758x16 -fbdir /srv/jenkins/xvfb-86-2156913754362856583.fbdir
Xvfb starting$ /usr/bin/Xvfb -displayfd 2 -screen 0 1024x758x16 -fbdir /srv/jenkins/xvfb-87-5845090375656014678.fbdir

One of the above 2 job instances fails. The failure message is this:

02:11:51 _XSERVTransSocketINETCreateListener: ...SocketCreateListener() failed
02:11:51 _XSERVTransMakeAllCOTSServerListeners: server already running

How can this error be fixed so that the concurrent instances run without any issue?

Further, I wonder how Xvfb plugin does the association of the display to the running browser instances (Firefox in this case). Does it do export DISPLAY=:xx internally, where xx = the display port as computed by the plugin?

Command line (not using Xvfb plugin)

The second way I tried is not to use the plugin and run Xvfb directly using the CLI. I used the Jenkins env variable BUILD_NUMBER to ensure unique display association to the job instance.

export DISPLAY=:${BUILD_NUMBER}
Xvfb :${BUILD_NUMBER} -screen 0 1024x768x24 &

Xvfb starts up fine in both job instances, but the tests fail with this.

Failed to connect to binary FirefoxBinary(/usr/local/bin/firefox) on port 7055; process output follows: 
Error: cannot open display: 0:0

It appears the tests are still trying to use display 0:0.

Any help to fix this problem is greatly appreciated.

1
Not sure about this, but on your command line implementation don't you need a unique number after the -screen argument as well? For example: Xvfb :${BUILD_NUMBER} -screen ${BUILD_NUMBER} 1024x768x24 &. I'm a newb to xvfb though, so I don't know for sure.NateW

1 Answers

1
votes

Have you tried to use Display environment variable in Jenkins, the same Xvbf has started with? In my case it worked and I followed the instructions, described in this article headless execution selenium tests in Jenkins