parroty / excoveralls

Coverage report tool for Elixir with coveralls.io integration.
MIT License
824 stars 180 forks source link

Incompatibility between excoveralls and meck? #308

Open binarytemple opened 1 year ago

binarytemple commented 1 year ago

Version information.

~/repos/bt/ecto_probe/ MIX_ENV=test mix  deps | egrep "(cover|meck|mock)" 
* excoveralls 0.16.0 (Hex package) (mix)
  locked at 0.16.0 (excoveralls) 40120535
* meck 0.9.2 (Hex package) (rebar3)
  locked at 0.9.2 (meck) 81344f56
* mock 0.3.7 (Hex package) (mix)
  locked at 0.3.7 (mock) 4da49a46

It seems from reading through the project issues that there might be an incompatibility between excoveralls, erlang cover module, and meck?

Running with mix coveralls :

~/repos/bt/ecto_probe/ mix coveralls
The database for EctoProbe.Repo has already been created

13:21:29.716 [info] Migrations already up
starting test_helper.exs
Starting tests
.........................

  1) test test the query router /query - no entries (EctoProbe.Plug.QueryRouterTest)
     test/ecto_probe/plug/query_router_test.exs:20
     ** (ErlangError) Erlang error: :killed
     code: test_with_mock "/query - no entries", Memory, [], query: fn _, _ -> [] end do
     stacktrace:
       (meck 0.9.2) /Users/b/repos/bt/ecto_probe/deps/meck/src/meck_proc.erl:93: :meck_proc.start(EctoProbe.Memory, [])
       test/ecto_probe/plug/query_router_test.exs:20: anonymous fn/2 in EctoProbe.Plug.QueryRouterTest."test test the query router /query - no entries"/1
       (elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
       test/ecto_probe/plug/query_router_test.exs:20: (test)

.........
Finished in 1.2 seconds (1.2s async, 0.00s sync)
35 tests, 1 failure

Randomized with seed 771179
Analysis includes data from imported files
["/Users/b/repos/bt/ecto_probe/Elixir.EctoProbe.Git.GitUtils.ConfReader.71485.coverdata",
 "/Users/b/repos/bt/ecto_probe/Elixir.EctoProbe.Git.GitUtils.ConfReader_meck_original.71485.coverdata"]
----------------
COV    FILE                                        LINES RELEVANT   MISSED
  0.0% lib/ecto_probe/git/git_utils/conf_reader       44       13       13
[TOTAL]   0.0%

Running with mix test


~/repos/bt/ecto_probe/ mix test     
The database for EctoProbe.Repo has already been created

13:21:35.985 [info] Migrations already up
starting test_helper.exs
Starting tests
...................................
Finished in 0.4 seconds (0.4s async, 0.00s sync)
35 tests, 0 failures

Randomized with seed 117515
parroty commented 1 year ago

Hi. Thank you for the report. Do you think it's possible to share example?

has meck dependency, but mix coveralls task is working at my environment.

$ MIX_ENV=test mix deps | egrep "(cover|meck|mock)"

...

* excoveralls (Hex package) (mix)
  locked at 0.14.4 (excoveralls) e3ab02f2
* meck 0.9.2 (Hex package) (rebar3)
  locked at 0.9.2 (meck) 81344f56
nietaki commented 1 year ago

I don't understand the inner workings of excoveralls enough to see if it's related, but just in case.

I'm running into a similar issue, where tests run through excoveralls fail, while they succeed when run with mix test, but in my case the conflict isn't with Erlang's meck, but redbug. Redbug uses Erlang's :code infrastructure which could possibly be affected by how excoveralls works (?)

binarytemple commented 1 year ago

This is not a specific issue with excoveralls, rather I failed to follow the guidance of the jj42/mock library author.

Specifically, I neglected to set the option use ExUnit.Case, async: false in my unit test.

Just running mix test didn't provoke the error, but the cleanup must have gone wrong and something (EctoProbe.Git.GitUtils.ConfReader_meck_original) hanging around for excoveralls to crash on.

From the jjh42/mock README ...

Currently, mocking modules cannot be done asynchronously, so make sure that you are not using async: true in any module where you are testing.

In case you are interested, I've included a minimal failing case (well, with 99% of extraneous code cut out).

ecto_probe.poc_excoveralls.zip

Thanks, Bryan

binarytemple commented 1 year ago