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

History item is not kept while module compiler is running #194

Closed
luos opened this issue Jul 13, 2018 · 3 comments
Closed

History item is not kept while module compiler is running #194

luos opened this issue Jul 13, 2018 · 3 comments
Labels

Comments

@luos
Copy link

luos commented Jul 13, 2018

Hi,

I am trying to use num_calls with a mocked function, but some of the history gets dropped. I identified the problematic part, which is here:

https://github.com/eproxus/meck/blob/master/src/meck_proc.erl#L308-L315

If Reload is set then the history doesn't get saved. Unfortunately for me it's not clear why this is happening, or if it's the intended way of working.

Reproduction Steps

I put a test repo here:
https://github.com/luos/meck-test

The test can be found in here:
https://github.com/luos/meck-test/blob/master/test/mt_reload_test.erl

Basically when an expect is set while something is calling the function some calls will be dropped even though seems to me the expect is working. Seems like a race condition in this compiler handling part?

Expected behavior

I expect that the history contains all calls to the function

Observed behavior

Usually the first call immediately after setting the expect is dropped.

Versions

  • Meck version: 0.8.6
  • Erlang version: 17.5, 20
@eproxus
Copy link
Owner

eproxus commented Aug 8, 2018

Finally got around to looking at this today. I couldn't reproduce it with the simple test on my (faster?) machine, so I had to create this monster version:

-module(mt_reload_test).
-include_lib("eunit/include/eunit.hrl").

-compile(export_all).

proc_fn() ->
    receive
        {do_call, Arg} ->
            ?debugFmt("[~p] called: ~p~n", [self(), mt_app:test_fn(Arg)])
    end,
    proc_fn().

reload_test() ->
    Proc = spawn(fun proc_fn/0),
    meck:new(mt_app, [passtrough]),
    meck:expect(mt_app, test_fn, fun(Arg) -> {mocked, Arg} end),
    spawn(fun() ->
            lists:map(fun(N) ->
                        timer:sleep(1),
                        Proc ! {do_call, N}
                     end, lists:seq(0, 800))
          end),
    [meck:expect(mt_app, test_fn, fun(Arg) -> {mocked2, Arg} end) || _ <- lists:seq(1, 5)],

    timer:sleep(4500),
    ?debugFmt("History: ~p~n",[meck:history(mt_app)]),
    ?assertEqual(801, meck:num_calls(mt_app, test_fn, '_'))
    .

I'm also not sure why the reload case is there, and why we don't store history while reloading is active (history is historical, so it should be stored regardless I think). By removing it, this test passes and it doesn't seem to break any other tests.

@eproxus eproxus closed this as completed in 70e3e30 Aug 8, 2018
@eproxus eproxus added the bug label Aug 8, 2018
@luos
Copy link
Author

luos commented Aug 8, 2018

Hi,

Thanks for checking and for the fix!

@eproxus
Copy link
Owner

eproxus commented Aug 8, 2018

@luos Thanks for reporting it and providing a base test case, very much appreciated!

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

No branches or pull requests

2 participants