This avoids calling Database#prepared_statement, which is slower as it uses a mutex. This also avoids a race condition if two threads try to prepare the same statement at the same time. That doesn't cause a problem, but it is still unnecessary work. The reason I didn't do this initially is it results in preparing statements even if you may not need to do so in the tests. However, I think the benefit of avoiding the mutex outweighs a minimal slowdown when running invididual tests that would load strand.rb but not call Strand#take_lease_and_reload. This also uses better mocking when testing this, so we are not mocking the prepared statement, we are actually causing a lease violation and ensuring that the prepared statement detects it.
5.1 KiB
5.1 KiB