Review Policy for Unit Tests in MailNews and Thunderbird

Now that we have some unit test structures in place for MailNews, we want to make it easier for new tests to be added, and clearer as to the required procedure.

Therefore, we have defined a Rules and Review Policy for unit tests that are to go into the source directories mailnews/ and mail/. This policy does not affect the existing review requirements for patches on the main code.

As I’ve said before, at the moment we still do not require unit tests with every patch as the full archecture is still being developed. We do however, strongly encourage unit tests where possible. If you need help, feel free to ping me (Standard8) on irc.

Score 1 for MailNews Automated Tests

After the mailnews/ and mail/ source trees reopened yesterday, I checked in a whole bunch of patches that had been queued up during the freeze. Some of them had been in my development tree, some of them hadn’t.

A little while later the SeaMonkey unit test tinderbox was orange. This surprised me, as I was fairly sure I had run all the mailnews tests with the various patches.

It turns out one of the patches (a follow up to bug 424570) had caused a regression where deleting address book cards wouldn’t work properly. This was one of those cases where before we had unit tests I wouldn’t have been surprised if we hadn’t detected the regression for a while.

So as Dan said, score 1 for MailNews automated tests. Although we’ve already seen regressions caught many times for the core tests, its good to see that the MailNews ones are now starting to catch regressions as well.

Soon to be a few less (minor) MailNews Memory Leaks

(I actually found the bugs a few days ago, but only just got round to blogging about it)

A couple of days ago, I was reviewing a patch and came across a function call to an interface of the type:

void foo(out unsigned long aCount, [array, size_is(count)] out bar aResult);

Where bar was an object derived from nsISupports. The aResult was being freed with NS_Free, instead of NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY. This would have ended up with MailNews leaking most of the objects in the array.

Being curious about where this came from, I did a quick search for the function, and found one instance already in the main code base, where we called NS_Free instead of the NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY. It wasn’t a major leak and would only happen on migration of some of the tag preferences, and for most users would probably end up being 300 bytes. However bug 431404 was raised, and that will soon be checked in.

Having realised that at least one instance in MailNews did this wrong, I did a quick audit of the other function calls in MailNews that obtain an array in the style above. A bit of searching later and I filed the patch on bug 431414, this fixes several leaks in migration, one potential leak in the LDAP autocomplete code, and two leaks related to getting/receiving mail.

The leaks I found when getting/receiving mail, really are small, effectively 4 or 8 bytes per message or newsgroup post, so you probably won’t notice too much difference. These also won’t show up on the Leak stats as we don’t currently receive messages in those tests (that is one of the things I want to extend those tests to do).

Improving MailNews performance, reducing leaks, bloat etc, is something I really want to see happen, this is one small step along the road, and I’ll certainly be looking out for more instances where we do our memory management wrong.