Most web sites end up needing some sort of background job queue to process requests that don’t belong on the critical path. In the Ruby on Rails world the two most common are Delayed Job and Resque. Writing tests for either is pretty straightforward with cucumber if you have your relational database (delayed job) or redis (resque) server already up and running.
Tddium takes care of starting and managing these services for you, so “no sweat!”, you think. Well, almost. These kinds of integration tests can be a pain to write accurately and reliably due to the asynchrony between the test and the background job queue.
The folks over at Square have a neat solution to this problem that we’ve adopted in our Cucumber tests: have a step that starts up a resque worker in the background and immediately stops it by sending it a signal. Then add a set of helper step definitions that allow you to clock the background job through your Cucumber test. You can read about the details in the Square blog post here or you can just grab the code from this gist.
Have a great hack for testing in the face of concurrency? We’d love to hear about it and better yet share it with the Tddium community!