The main concept of a Test Lock is basically a mutex between the thread running the tests and the thread handling the server requests.
Our main issue had to do with our teardown destroying database records while a request was ongoing. It's extremely tricky to debug because it's entirely timing based. (Request begins, before_actions are happy, teardown begins, records are destroyed, request sometimes freaks out).
So the idea is that once we TestLock.join
, we flip a gate that disallows any new requests, and blocks until the existing request is complete. Then we know we can safely purge the database (and other elements).