I’ve been working a a ruby project using rspec for the tests and I got stumped pretty good today. The symptom was that tests would randomly fail for a variety of reasons. Many were because temp files were disappearaing. I decided to spend some time refactoring the tests first to get things a little cleaner and this helped a little. The symptom that became more obvious after rework and putting some debug “puts” in was that at a random point, the tests would start duplicating. Adding a semaphore/Mutex didn’t make any difference. Same test, same thread, same mutex. Still duplicated.
After a lot of digging and searching for problems with rspec, rcov, rake and their interactions I came across this post – http://blog.hiremaga.com/2008/01/31/dont-get-forked-by-rspec/ .
There was indeed a test that was calling a class that daemonized itself by calling fork. Unfortunately changing the at_exit as suggested does not work in my case. Adding a boolean to allow skipping the fork during testing works sufficiently to keep rcov happy.
All tests green again.