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.

No comments:

Post a Comment