Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async tests using Bypass interfere with ExVcr tests #192

Open
maxmarcon opened this issue Jan 4, 2023 · 3 comments
Open

Async tests using Bypass interfere with ExVcr tests #192

maxmarcon opened this issue Jan 4, 2023 · 3 comments

Comments

@maxmarcon
Copy link

maxmarcon commented Jan 4, 2023

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)

@kacorvus
Copy link

kacorvus commented Jan 9, 2023

This is a wild guess, but maybe try "clear mock" as mentioned in this issue: #136 ?

@maxmarcon
Copy link
Author

Thanks. I tried but it doesn't work. And it makes sense: the tests are running concurrently, so clearing the mocks after a test doesn't guarantee in any way that another test running concurrently won't use the mocks

@kacorvus
Copy link

Discussed in elixirforum - https://elixirforum.com/t/approach-for-numerous-edge-cases-http-get-exvcr/50291/15?u=kanishka - probably resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants