Halo: Fix function mocking to not throw error if backup exists.

If a test fails that created a function mock, it doesn't unmock it.
So rather than fail on a subsequent test as well, check whether the
backup still exists and use that instead of trying to create it
again.
Gravity: Method for handling deadlocks and reexecuting the query