exvcr icon indicating copy to clipboard operation
exvcr copied to clipboard

Async tests using Bypass interfere with ExVcr tests

Open maxmarcon opened this issue 1 year ago • 3 comments

First of all, thanks for creating this library! I really want to use it as I feel it would allow me to write tests that interact with external APIs more efficiently than with my current approach.

What is my current approach? I use Bypass.

So right now I have a bunch of legacy tests for different REST APIs that use Bypass. My HTTP client is Tesla + Finch.

I wrote a test for a new API using ExVcr. When I run the ExVcr test asynchronously together with the other async Bypass-based tests, some of the Bypass tests always fail. Which tests exactly fail is random and depends on the order of execution I guess. If I run the ExVcr test with async: false everything is fine.

What could be the reason behind this issue? My understanding is that ExVcr mocks the functions in the Finch module. Are these mocks global? If that's the case then it's no surprise that the other async Bypass-based tests occasionally fail, because they need to hit the real Finch implementation to talk to the Bypass server.

Am I right in this assumption? If so, is there a way to restrict the mocks to the current test only, so that other tests running in parallel will use the real implementation?

this is the preamble of my test file:

  use ExVCR.Mock, adapter: ExVCR.Adapter.Finch

  setup do
    ExVCR.Config.cassette_library_dir("test/fixtures/vcr_cassettes/onit")
    ExVCR.Config.filter_request_headers("authorization")

    :ok
  end

I have no global config for ExVCR.

For Tesla I have this in my config:

config :tesla, :adapter, {Tesla.Adapter.Finch, name: DataIngestion.Finch}

And I start the Finch process with this child spec in my application.ex:

{Finch, name: DataIngestion.Finch},

(All very standard as you can see)

maxmarcon avatar Jan 04 '23 12:01 maxmarcon