+
Skip to content

Num_calls increments when called function returns #165

@guess-burger

Description

@guess-burger

It appears that the value returned by meck:num_calls(...) only updates after the called function has returned. This makes verifying behaviour around long running functions difficult.

Reproduction Steps

Here's a passing eunit test to recreate the scenario I have.

num_calls_test() ->
  meck:new(dummy, [non_strict]),
  meck:expect(dummy, test, fun
                             (short) -> ok;
                             (long) -> receive stop -> ok end
                           end),

  ?assertEqual(ok, dummy:test(short)),
  ?assertEqual(1, meck:num_calls(dummy, test, [ short ])),

  Pid = spawn(fun() -> dummy:test(long) end),
  timer:sleep(100),
  ?assertEqual(0, meck:num_calls(dummy, test, [ long ])),
  Pid ! stop,
  timer:sleep(5),
  ?assertEqual(1, meck:num_calls(dummy, test, [ long ])),

  meck:unload(dummy).

Expected behavior

I would expect that meck:num_calls would update as soon as the function is entered and the runtime of that function to have no effect. I would exepect the first call to ?assertEqual(0, meck:num_calls(dummy, test, [ long ])), to fail with a value 1 being returned instead

Versions

Meck version: 0.8.4
Erlang version: 18.2.1

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载