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

Tests sometimes fail with ** (MatchError) no match of right hand side value: false #111

Open
Victoria91 opened this issue Nov 1, 2019 · 4 comments

Comments

@Victoria91
Copy link

In some our tests we have plenty of mocks and sometimes tests fail with

     ** (MatchError) no match of right hand side value: false
     code: with_mocks(mocks) do
     stacktrace:
       test/test.exs:267:  <line with `with_mock` call>
       (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3

Everything is defenitely Ok with mocks itself - tests usually pass, but still it is rather annoying when you have lots of such tests and they sometimes fail for no reason :(

@Olshansk
Copy link
Collaborator

Olshansk commented Nov 2, 2019

So is the same test failing/passing ephemerally?

Could you provide some example code so we can debug together?

@Victoria91
Copy link
Author

Here is shortened version of test that still reproduces the error, I hope It will be engouh.

Here is is sample of failed test output

  1) test #init assert 6 (MyAppRouter.ConsumerListenerTest)
     test/consumer_listener_test.exs:101
     ** (MatchError) no match of right hand side value: false
     code: with_mocks(mocks) do
     stacktrace:
       test/consumer_listener_test.exs:104: anonymous fn/2 in MyAppRouter.ConsumerListenerTest."test #init assert 6"/1
       (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3
       test/consumer_listener_test.exs:104: (test)

And one more detail: Our project uses umbrella. The case with flicker failing tests reporoduces only when running tests from the root direcrory of the whole project. When running from the directory of the application with specific test - the test always pass

@Olshansk
Copy link
Collaborator

Olshansk commented Nov 9, 2019

Hmm...

Given that you said this: When running from the directory of the application with specific test - the test always pass and looking at the test you pasted, the only theory I have is that your tests are asynchronous, so there's a weird race condition happening when you are trying to mock things.

Can you try updating this line with use ExUnit.Case, async: true and see if the error persists?

Reference: https://hexdocs.pm/ex_unit/ExUnit.Case.html

@Victoria91
Copy link
Author

No, tests are not asynchronous, if add async: true, that way they will be asynchronous and they won't pass at all but with other errors.
Sorry for late reply

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