I’m currently writing a test suite for a Stripe library, using the stripe-mock tool which is a “fake Stripe” as a simple Go binary.
I’m using a GenServer to manage this process while the tests are running. I have a StripeMock.reset/0
which essentially kills and restarts the process synchronously. This takes anywhere between 250–1000ms and so I don’t want to do that between every single test (though I already do it in setup_all
).
However, there are certain tests, such as ones which test deletion of objects, after which I’d like to reset the mock server. I’m actually not certain if I need to do this (not sure if stripe-mock actually persists the deletion), but either way while trying to work this out I realised I could not figure out a good way, which may be a shortcoming.
on_exit
runs asynchronously in a different process, and so does not work—it can run concurrently with more tests executing. One convoluted solution I can think of is to use some sort of global process to manage a lock which on_exit
sets and setup
waits on, but it seems like there should be a better way to do synchronous teardown.
Am I missing something?