Looking for a Devops Engineer / Release Manager @tuenti.com

We are looking for a Devops Engineer / Release Manager here at http://www.tuenti.com.

Join our amazing Devops team to improve the development workflow of more than 150 engineers, to write tools to automate EVERYTHING within this company like a single button to push code to live or a tool to merge branches automatically and to manage the releases we do almost everyday pushing code to more than 14 million users.

Enjoy this company: international environment ( people from more than 20 countries ), football table, ping-pong, beer+pizza every friday afternoon, trips, young and very talented people, etc.

Check the offer out or contact me!! http://corporate.tuenti.com/es/jobs/opportunities/offer/69

The Python Jenkins API

In this post, i’m going to show you a very useful tool to manage Jenkins using Python.

As you probably know, Jenkins offers a cool API in XML, JSON and Python, if you don’t know it yet, take a look to its documentation, you will love it:

https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

Almost every programming language can handle JSON and XML rest APIs but i’m going to take advantage of the Python API because i love this language.

There exists a project called jenkinsapi written in Python that ease the usage of the API:

https://github.com/salimfadhley/jenkinsapi

I’ve been contributing to this tool, specially with the part of handling downstream and upstream jobs.

With this tool you can manage Jenkins in a very easy way, for example, if you want to know the status of the last build of the job “MyAwesomeJob”, you just need this dummy code:

from jenkinsapi import api
jenkins = api.Jenkins('http://your-jenkins-server/api/python/')
awesome_job = jenkins.get_job('MyAwesomeJob')
awesome_build = awesome_job.get_last_build()
if awesome_build.is_good():
    print "The build passed successfully"
else:
    print awesome_build.get_status()

Continue reading

After Selenium Conf 2012

I’m one of the guys who went to the Selenium Conf 2012 in London and it was awesome!

Very good talks and very nice people, congratulations to the organizers and specially to Simon Stewart and Jason Huggings.

I could write lots of things of what i saw there, but i don’t have much time so i’m going to write some brief conclusions:

  • Most of the top tier companies test their software in a ( more or less ) similar way, which indicates that the testing world is going through a single line and this involves very good things such a future standardization and good cooperation between people within this testing world. Great news.
  • In my current job at Tuenti, we are also in the same page. We achieve, in some cases, better results and have a better testing framework/infrastructure than some companies that are in the same vein. That thing made me feel very proud and happy of what we are doing at Tuenti.
  • Everyone has problems with their tests:
    • slowness
    • flakiness
    • brittle tests
    • undeterminism produced by AJAX asynchronous requests
    • DOM changes made by the developers and its consequent test update
    • Third party elements in tests
  • Some of them could (kind of) fix their problems, but there isn’t a good nor standard solution for all these problems. Here, the testing world has a big room of improvement.  I have some ideas for some of them.
  • Surprisingly for me, Cucumber ( or at least BDD ) is being more and more popular.

When i was seeing some of the talks, i though that maybe in the future i can write an article or even do a talk of how the testing at Tuenti has evolved since my first days in October 2009, some points:

  • We ran 400 tests in 3 hours, now we run 11000 in 23 minutes
  • We used Cruisecontrol, now we use Jenkins
  • Every release we had about 40 tests out of 400 failing randomly due to an important flakiness, now, helped with some magic tricks, i’m proud to says that zero tests fail out of 11000

Triggering Jenkins jobs from the SCM push to avoid the evil polling

Why?

If you have a continuous integration infrastructure with Jenkins you might have you jobs configured to make polling over your SCM in order to trigger a job when there are changes. But this has some problems when Jenkins has several nodes and there are a big amount of jobs.

In my case, i configured the Jenkins jobs to poll the SCM repository ( Mercurial ) every 5 minutes. What that means?

  • A very big load in the SCM repository server due to the big amount of pollings from every Jenkins job.
  • Unexpected behaviour of the polling due to Jenkins bugs or SCM plugin bugs ( at least in the Mercurial one )
    • Jobs launched with no changes because the polling couldn’t be done because maybe the workspace of the previous build is not available
    • Jobs not launched although there are changes because of the loss of threads that manage the channel connections between the master and the slaves (Jenkins bug)

Continue reading

Installing Google Chrome in Debian Lenny

If you are thinking about installing the newest version of Google Chrome in Debian Lenny, don’t waste your time, you can’t (actually, you can but i don’t think you want to compile every package dependency).

The Google Chrome team is not supporting Debian Lenny and the latest package version supported is Google Chrome 12.

The package depends on other packages that are not in Debian Lenny anymore, there isn’t even a backport package for some of them. So, if you want this browser in the “super stable” Lenny version, you need to be satisfied with the version 12.

And if you really need the newest version, upgrade to Debian Squeeze. The installation in Squeeze is pretty straightforward, just install the .deb and resolve the dependencies:

dpkg -i google-chorme-latest-version.deb
apt-get -f install

I couldn’t find older packages in the Google Chrome page, so here you have a link to the 12 version:

Arch AMD64: http://linuxfreedom.com/hacktolive/repo/archive/pool/main/g/google-chrome-stable/google-chrome-stable_12.0.742.112-r90304_amd64.deb

Arch i386: http://linuxfreedom.com/hacktolive/repo/archive/pool/main/g/google-chrome-stable/google-chrome-stable_12.0.742.112-r90304_i386.deb

Fixing the postbuild order problem of the upstream/downstream solution i wrote

Some days ago i wrote a post about how to get the overall status in the upstream job from the downstream jobs in Hudson or Jenkins (https://fatalfailure.wordpress.com/2011/06/14/jenkins-hudson-getting-the-overall-status-in-the-upstream-job-from-the-downstream-jobs/).

A user (v22 ) test my code and had some problems, and actually, there is a problem.

As i said in the comment reply, there is a problem in the execution order of the post build actions, this is not deterministic and depends on how the job configuration is stored in a XML file located in the master node.

The relationship between the upstream jobs and the downstream jobs is ready when the fingerprints are recorded. This action is done on a post build action, like the Groovy execution. If the Groovy execution is performed before the fingerprint recording, there is not upstrem job set yet, therefore the Groovy code fails.

I proposed in that reply a workaround to change the order execution of the post build actions, but this is not working as i expected, so there is not a way to force the Groovy execution after the fingerprint recording.

There is an open ticket in the Jenkins and Hudson issue tracker to add a way to specify the post build actions executions: https://issues.jenkins-ci.org/browse/JENKINS-7408

But everything has a solution, and a solution that always works 😉

Continue reading

Detecting slow tests with PHPUnit

Edit: As Sebastian Bergmann told me via Twitter, PHPUnit already generate timing information into the JUnit XML logs, but the idea of this post is the earlier detection of slowness in tests, i mean, you are developing tests and you are executing them, thus you will detect quickly if the tests are exceeding a time limit.

The tests, in most of the cases, are written by developers. Sometimes, they don’t take care of the speed of those tests.

We, as test engineers, should detect, or even prevent, the slowness in tests.

PHPUnit let you use listeners to add logic in some parts of the test execution, therefore, you can detect when a test starts and finish.

The listeners are PHP classes that must implement the PHPUnit_Framework_TestListener interface, to use them you will need to create a XML configuration file passed as a param to the PHPUnit runner.

Type in your shell:

phpunit --configuration MyConfiguration.xml testsDirectory

Continue reading

Jenkins / Hudson getting the overall status in the upstream job from the downstream jobs

Few days ago i asked in http://www.stackoverflow.com this question:

http://stackoverflow.com/questions/6141003/jenkins-hudson-upstream-job-does-not-get-the-status-ball-color-of-the-downstrea

I wanted to get the result of the upstream job depending on the result of the downstream jobs. I mean:

If in the upstream job i get a “stable” result but if in one of the downstream jobs i get an “unstable” or “failed” result i want to get the worst status in my upstream job.

In my case, i wanted to speed up the test execution paralellizing the build in different downstream jobs, therefore, i wanted to have the overall result of the build in the main job (the upstream) in order to see the result of the complete build in a single point.

I couldn’t find any good solution, only workarounds. So i started to investigate and discovered the best Jenkins / Hudson plugin i have ever seen: the Groovy Postbuild plugin

https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin

With this plugin you can do almost whatever you want with Jenkins / Hudson. It allows you to execute a Groovy script in the post build phase and offers you the “build” and “hudson” Java objects.

The solution for my problem was a simple Groovy script added in the downstream jobs. This code gets the upstream job, access to the last build, check the result and if its result is better than the downstream one, it updates it.

This is the piece of code:

Continue reading

PHPUnit and the Fatal error: Call to undefined method

PHPUnit+Selenium+Fatal errors:

Once upon a time i was writing and executing some Selenium acceptance tests using PHPUnit and i realized that PHPUnit detects fatal errors due to an undefined method and convert them into exceptions. Good feature! i though, if you have a fatal error in your test the process execution  doesn’t stop, the log is generated and the rest of the tests can finalize. But i started to investigate the PHPUnit code and i saw that the detection of the fatal error might be done by sheer chance.

The PHPUnit SeleniumTestCase driver has a well known list of valid commands to send to Selenium, if you send an invalid one from your test it will be detected and the exception is thrown. How PHPUnit detects it? using the magic function “__call”, each command the driver receives goes through this magic function and switch it to see if the command is contained in the list of commands.

Although i don’t like the PHP magic functions and i think this conversion from the fatal error to the exception was not on purpose, the result is good and gives us a better way to handle the “undefined method” fatal errors because the process execution is not stopped and the test result follows the PHPUnit format therefore is easily readable.

But the behaviour is not always like this, what will happen if you are delegating test responsabilities to other external classes? maybe because you are using the Page Object pattern or just using helpers.

Continue reading

AJAX + Selenium: solution for race conditions

There exists a problem with the race conditions testing websites full of AJAX, here is a solution using Selenium.

I’ve been looking for the perfect solution of the pair “AJAX + Web testing tool” and i’ve reached the conclusion that, so far, there isn’t a perfect solution.

Selenium is ready (at least almost ready) to test AJAX websites and apparently, Selenium is the most used tool and has the biggest support community, and therefore, is the better one to deal with AJAX applications.

As probably many of you know, Selenium has methods like “waitForXXX” that can assert most of the AJAX request and if your website renders the code statically or dynamically just some pieces of the site, you won’t have any problems.

But what happens if your website is full of AJAX and all the source code is generated dynamically? I mean, for instance, the JavaScript events.

I’m not an expert in HTML or JavaScript but i’m talking about the onclick, onmouseover, onload, etc. attributes of the HTML tags. Usually, these attributes have JavaScript events that perform a change in the site.

BUT, if these JavaScript events are loaded dynamically and asynchronously using an AJAX request, is Selenium able to perform proper assertions? NO.

Continue reading