[ExUnit] Run a synchronous teardown?

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?

@mjadczak have you found a solution since?

I’m making a e-commerce website and for tests I have to use the same Golang stripe-mock, and have run into the predicament of having to run a server like your situation.

Also in your approach - how did your GenServer run the golang server? Just a cmd call?

I was also thinking about doing what the recent Tailwind library (tailwind/tailwind.ex at master · phoenixframework/tailwind · GitHub) does to install the Tailwind CLI in _build, so as to make the installation of the golang server more streamlined… but that is tangent to the discussion.

No matter how it is installed, I’m at a loss as to how to use it during tests, without having to manually start the server (which will be problem during CI)

Thanks in advance!