meck icon indicating copy to clipboard operation
meck copied to clipboard

Getting meck_proc already started errors

Open SoniCoder opened this issue 3 years ago • 7 comments

Expected behavior

make eunit/junit COVER=1 should pass post OTP 23

Observed behavior

Getting these kinds of errors (with COVER=1) for some unknown reasons that were not coming before OTP 23

::in function meck_proc:start/2 (src/meck_proc.erl, line 93) called as start(put_functions,[passthrough]) **error:{already_started,<0.16752.0>}

This only happens with COVER=1 and succeeds when COVER=1 is not specified

Versions

  • Meck version: hex 0.8.13 (have tried 0.9 as well)
  • Erlang version: OTP 23.1.1

OS: Debian Buster Erlang OTP 23.1.1 installed(compiled) via. kerl

SoniCoder avatar Oct 27 '20 16:10 SoniCoder

Not sure how to reproduce this. What project are you building and how?

eproxus avatar Feb 17 '21 10:02 eproxus

The project is private. However we have noticed that it doesn't always happen (only sometimes perhaps due to some race conditions) and only happens with cover even though we are doing teardown of that module's meck properly using meck:unload() every single time.

SoniCoder avatar Feb 17 '21 10:02 SoniCoder

Are you running tests in parallel? This error occurs when there's already a mock started for the module. Alternatively, perhaps you have a cleanup that doesn't always run properly?

eproxus avatar Feb 17 '21 14:02 eproxus

Not specifying any execution order and letting eunit decide everything. Have my cleanup (meck:unload()) in a try catch after block ... so as long as the cleanup function executes, I think meck:unload() should be always called. Not sure how cover sometimes interacts with all of this in a funny way.

SoniCoder avatar Feb 17 '21 14:02 SoniCoder

Sounds like a race condition somehow (asynchronous teardown of a mock at the same time as a set up). Does the error happen if you run individual test cases in isolation?

eproxus avatar Feb 19 '21 13:02 eproxus

have noticed this while running the individual test as well

SoniCoder avatar Feb 19 '21 14:02 SoniCoder

Getting this issue when running just one test sounds really weird, especially if you never called meck:new() before. Can you reduce the test to something minimal that I could reproduce?

eproxus avatar Feb 20 '21 12:02 eproxus