Behat Parallelization Series: Episode I – Setting Out For San Francisco

Sometimes is time to parallelize work. This is needed because you want to speed up development by having two folders or more. The same project, same files almost, but different branches in each folder, therefore, different development stages and testing at the same time. How can this be possible since there could be many conflicts? Keep reading.

~ cp -rf ~/sites-2/project1 ~/sites-2/project1-running-tests
~ /sites-2/project1 (feature/branch1)
~ /sites-2/project1-running-tests (develop)

This implies you have copy the same folder twice and they are now totally independent. You of course are pushing to the same git repository but they are coming from different development stages. There could be total decoupling when you have set db names for each instance different, and of course also vhost settings have to be different as well in order not to interfere between runs. This last can be achieved with some scripting and randomization (more on that later).

You also want your behat suite to run on the background so no popups or anything shows up to distract you from your work. That is achieved with xvfb. How to set it up with all the misinformation? Keep reading.

Copy this script into `/etc/init.d/xvfb` :

#!/bin/bash
### BEGIN INIT INFO
# Provides:          Xvfb
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Xvfb.
# Description:       Start the X virtual framebuffer.
### END INIT INFO

XVFB=/usr/bin/Xvfb
XVFBARGS=":5 -nolisten tcp -fbdir /var/run"
PIDFILE=/var/run/xvfb.pid
case "$1" in
    start)
        echo -n "Starting virtual X frame buffer: Xvfb"
        start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
        echo "."
    ;;
    stop)
        echo -n "Stopping virtual X frame buffer: Xvfb"
        start-stop-daemon --stop --quiet --pidfile $PIDFILE
        echo "."
    ;;
    restart)
        $0 stop
        $0 start
    ;;
    *)
        echo "Usage: service xvfb {start|stop|restart}"
        exit 1
esac
 
exit 0

Run then:

sudo chmod u+x /etc/init.d/xvfb
sudo update-rc.d xvfb defaults
sudo service xvfb restart

Now tell sahi you want it to run into :5 display with a new setup called chromeBg (Bg for background):

~ pico ~/sahi/userdata/config/browser_types.xml 
// and add a browser type entry:
        <browserType>
                <name>chromeBg</name>
                <displayName>ChromeBg</displayName>
                <icon>chrome.png</icon>
                <path>env DISPLAY=:5 /usr/bin/google-chrome</path>
                <options>--user-data-dir=$userDir/browser/chrome/profiles/sahi$threadNo --proxy-server=localhost:9999 --disable-popup-blocking</options>
                <processName>chrome</processName>
                <capacity>5</capacity>
        </browserType>

Then make sure you tell your behat configuration behat.yml or other in symfony2 to have a sahi browser:

mink:
    // ...
    goutte:     true
    sahi:       ~
    browser_name: chromeBg

Now that your behat tests are running in one folder then you can calmly work on your other folder without interruptions and interference by fixing tests, doing more develop, etc. On our next series we will consider this in the greater scheme of things.

I have a request, please donate so i can afford training in SymfonyLive in San Francisco. Currently the price for training is 290EUR. And I already spent a lot on my air ticket. If you would like me to share more tips and continue to blog please support me here is the link http://bit.ly/9xbyzM . Thanks!

Looking forward to more!

One thought on “Behat Parallelization Series: Episode I – Setting Out For San Francisco

Leave a Reply to instrukcja pit 28 Cancel reply

Your email address will not be published. Required fields are marked *