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

Test failing with not_mocked #144

Closed
mitchellwrosen opened this issue Jun 8, 2015 · 4 comments
Closed

Test failing with not_mocked #144

mitchellwrosen opened this issue Jun 8, 2015 · 4 comments
Labels

Comments

@mitchellwrosen
Copy link

reconnect_success_test() ->
    meck:new(ejabberd_dekaf_client, [passthrough]),
    meck:expect(ejabberd_dekaf_client, do_connect, fun(_,_,_) -> {ok, pid} end),
    {ok, Pid} = ejabberd_dekaf_client:start_link("foo", 0, <<"bar">>),
    ok.

This test is crashing (after succeeding) with:

=ERROR REPORT==== 8-Jun-2015::20:06:47 ===
** Generic server <0.1602.0> terminating
** Last message in was {'EXIT',<0.1594.0>,normal}
** When Server state == {state,"foo",0,<<"bar">>,pid,true,1}
** Reason for termination ==
** {{not_mocked,ejabberd_dekaf_client},
    [{meck_proc,gen_server,3,[{file,"src/meck_proc.erl"},{line,437}]},
     {meck_code_gen,exec,4,[{file,"src/meck_code_gen.erl"},{line,147}]},
     {gen_server,terminate,6,[{file,"gen_server.erl"},{line,722}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}

For some reason, if I shorted the test a bit, it passes:

reconnect_success_test() ->
    meck:new(ejabberd_dekaf_client, [passthrough]),
    meck:expect(ejabberd_dekaf_client, do_connect, fun(_,_,_) -> {ok, pid} end),
    ok.

Thanks for looking.

@eproxus
Copy link
Owner

eproxus commented Jun 9, 2015

Since I don't know what ejabberd_dekaf_client:start_link/3 does, it's hard to tell what goes wrong here. Would you happen to have any more stack traces available? I suspect the not_mocked error is thrown from the Meck API (or a call to a mock) from inside your gen_server somewhere (hence the Generic server ... terminating message).

@mitchellwrosen
Copy link
Author

Hm. start_link traps exits, which seems to trigger the error. Here's the whole code:

-module(ejabberd_dekaf_client).
-behavior(gen_server).

start_link(_,_,_) -> gen_server:start_link(?MODULE, {}, []).
init(_) ->
    process_flag(trap_exit, true),
    {ok, foo}.

@eproxus
Copy link
Owner

eproxus commented Jun 10, 2015

Could it be that because you trap exits, the process doesn't die when the test is over and it continues to call the mock (which is gone since the test is over)?

@eproxus
Copy link
Owner

eproxus commented Nov 21, 2016

Closing because of inactivity. Please re-open if it is still an issue!

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