Archive for December, 2009

Block on test failures

I can’t stress enough how important it is to automatically block, stop the line, when a regression occurs. Forcing someone to take action. Don’t think it’s enough to have tests to catch regressions. It won’t help you much, unless you run them automatically, and most importantly, block on test failures, forcing someone to fix them.

In Launchpad we have been quite good at this in the past. Already from the beginning we ran the whole test suite before every commit. If a test failed, the commit wasn’t made, and the committer had to make the test pass before being able to commit those changes to the mainline. Now we have something similar. For performance reasons, instead of running the tests before the commit, we run them after. If a test fail, we enter testfix mode, blocking all commits to mainline, until the test passes again.

But, when we decided to bring in AJAX into the equation, we failed to do the same for the new test infrastructure we added. We use Windmill to test our AJAX functionality, and since it was a bit flaky, and it wasn’t trivial to integrate it into our existing test suite, we thought it was enough to be able to run the tests manually to avoid regressions. This was a big mistake. Not many people are going to run the tests manually, so regressions are bound to sneak in without you noticing it. Believe me, I know. I integrated the Windmill tests into our normal zope.testing test runner. When I did this, I found out that a lot of our Windmill tests were actually failing. We set up a buildbot builder to run the Windmill automatically, hoping that it would make regressions less likely to be introduced without us knowing about it. It helped a bit, we actually did catch a few regressions, but it was hard manual work. It required someone (me!) to keep an eye on the buildbot runs, looking through the test log, and chase people to fix it. This led to having not all the tests passing most of the time, which made it even harder to notice new regressions. So while simply having the tests run automatically helps a bit, it still requires a lot of discipline and manual work to prevent regressions from being unnoticed.

That’s why I’m pleased to announce, that Windmill tests are now included in the regular Launchpad test suite, which means that when a Windmill test fails, we will enter testfix mode and we’re forced to take action. It will be a bit painful in the beginning. I’m sure that we will see some spurious test failures. However, I’m sure it will be less painful that it has been to keep the current Windmill test suite under control.

The next time you add new testing infrastructure, let’s include it in the regular test suite from the beginning, OK?

Think about integration issues

When doing work on something that is supposed to be used by others, don’t forget to think about how it’s actually going to be used. Not only to think about it, but to actually try it out, to confirm that it works nicely when integrated, and that it’s easy to integrate it. And let’s not forget to document how to integrate it, and ideally to test it as well.

As an example, in Launchpad we use lazr-js for our Javascript infrastructure. We recently changed the way it’s integrated into Launchpad, giving it a proper setup.py file, so that we can generate an egg and depend on it through Buildout. The integration issue was of course taken into account there, making sure it was easy to build lazr-js both standalone, and when used in another project, like Launchpad. There was one command to build everything, which is simple enough. However, one thing wasn’t done. It wasn’t documented how you should use lazr-js in another project. Therefore, when people continued to develop lazr-js, adding more features, and making the build system more complicated, there wasn’t much thought about keeping it easy to build lazr-js in other projects. The build process became more complicated, multiple commands had to be executed. This is fine when building lazr-js by itself, since all you have to do is make build. However, when using lazr-js as an egg, you don’t have access the Makefile, which means that you have to duplicate the build steps. Therefore, having the build to be more than one command, makes it harder to use elsewhere. In fact, the build process of lazr-js changed so much, that we didn’t know anymore, how to properly use the latest version of lazr-js in Launchpad.

This is just one example of integrating external libraries. But the same is true for code internal to the project. When developing code that is to be used by multiple call sites, it’s important to think about how it’s actually going to be used. It’s easy to get carried away, developing a, what you think, really nice API. But then when people start to use it, it turns out that it’s not so nice.

What can be done to avoid integration issue? Ideally, you should document and test how the integration is supposed to work. By doing this, you get a feel of how to use the API. Doctests are actually quite nice for this purpose. If you manage to produce a readable doctest, it’s quite probable that your API is easy enough to use.

Sometimes adding tests for integration isn’t feasible. For example, in the case of lazr-js is not that easy. What I do when I develop on lazr-js is to have a throw-away Launchpad branch, where I use my lazr-js branch and manually make sure that it works nicely when integrated. Take a look at how it looks when integrated. What steps do you have to do to use it? Is that something that you will want to do for every call site? Are people likely to copy and paste an existing example to use your code? If the answer to the last question is yes, it’s not easy to use your code.

Wanted: bzr plugin to manage branches in Launchpad

I will probably implement this myself at some point, but if anyone wants to use their bzr and launchpadlib skills to make the world a slightly better place, I’d be grateful. You don’t even have to have any bzr and launchpadlib skills, both are quite easy to get started with. This could be a great opportunity to learn more about them!

I want a bzr plugin that queries Launchpad and list all my branches that aren’t Merged or Abandoned. I want it to work in the context of a branch, so that it automatically knows which project I’m interested in, although having it work outside a branch and list branches for all my projects would be useful as well.

To remove branches from the list of active branches, I’d also like to be able to mark a branch as Abandoned using the plugin.

Bonus points if any attached merge proposals and their status also are listed.