slindner

Fix failing parallel running browser tests with Gitlab & Robotframework

One of our project is organized in sprints where all developer work on the same code at the same time. We use one Gitlab CI server with a simple shell executer and had random failing builds with Robotframwork & Firefox.

Our Gitlab CI Runner can run three shell executer at the same time. Sometimes two Robotframework (Selenium) tests run in parallel and one of them fails with this error:

error: [Errno 98] Address already in use

That means Firefox is already in use (by the other build) and the CI job failed and blocked our process. Gitlabs automerge -feature does not happen and the code-reviewer needs to manually start the job again since it is marked as a fail.

We solved the problem with a little shell script isfirefoxinuse.sh that waits if a Robot process is running:

#!/bin/shwhile :do RESULT=`pgrep -f robot` if [ "${RESULT:-null}" = null ]; then echo "Robot not running, starting " ./bin/test --all -t robot || exit 1 break else echo "running" fi sleep 20done

Our .gitlab-ci.yml file looks like this:

before_script: - export PATH=$PATH:bin/ - export DISPLAY=:99build_project:# stage: build script: # Stage: build - /usr/bin/virtualenv . - ./bootstrap_ci.sh # Stage test - ./bin/code-analysis - ./bin/i18nize_all && ./bin/podiff_all - ./bin/coverage erase - ./bin/coverage run -p --source=src bin/test || exit 1 - ./bin/coverage combine - ./bin/coverage html - ./bin/coverage report # Stage robot - ./bin/isfirefoxinuse.sh || exit 1 artifacts: expire_in: 1 week paths: - parts/test/

The call to start the robot tests (./bin/test --all -t robot) is wrapped into the ./bin/isfirefoxinuse.sh script.

If you are a buildout user, this might be useful to get the script integrated:

parts += isfirefoxinuse
...recipe = collective.recipe.cmdon_install = trueon_update = truecmds = cp ${buildout:directory}/templates/isfirefoxinuse.in ${buildout:bin-directory}/isfirefoxinuse.sh

 Hope this helps someone!