Showing posts with label unit tests. Show all posts
Showing posts with label unit tests. Show all posts

Sunday, May 31, 2009

Race Conditions

I solved the strange error that I had in a unit test but I'm not completely satisfied with the solution because it limits what I can do in a unit test.

The error looks like a race condition due the tests running on NFS. The tests in question are actually functional tests that run a command line utility to validate the behaviour. The utility manipulates a SQLite database and two of the tests use direct access of the same database to either initialize or verify the contents. The external process terminates so it will always release all access to the database, but the tests run in the same process which does not end until all tests have completed. The tests do close the database which should release the resource, but this takes longer to propagate on NFS, so the process is still marked as accessing the file when the test fixture setup runs to reinitialize for the next test. Obviously you can't remove a file when it is still open, so the setup crashes.

For the time being I'm avoiding direct access to the database in the functional tests, until I can figure out how to get around this problem. The functional tests should simulate user actions only so direct access to the database isn't really necessary here, but it does make the tests more complete. Oh, well you can't have everything.

Wednesday, February 25, 2009

Coding To Relax

I actually did some coding on Tom's TV Utility for a few hours over the last couple of days. It was strangely relaxing. I wonder if coding uses a different part of the brain than solving sysadmin problems. I doubt it but it was nice to work on something and see some progress after a few hours effort. I am writing functional tests for the command line interface, so it certainly wasn't difficult. I'm sure as I get deeper into the design it will become frustrating as well. At least there is no outside pressure so that will help.

I'm using a new testing framework for command line scripts that I found in the Paste project. It works well so far but I haven't really tried everything yet. I write a lot of command line programs and having a helper which hides the sub process calls makes the tests a lot easier to read.