[erlang-questions] testing side effects of asynchronous code
Mon Jan 2 12:20:56 CET 2012
On Mon, Jan 02, 2012 at 11:02:47AM -0000, Gustav Simonsson wrote:
> You could use meck and do a manual passthrough, i.e. something like:
> meck:expect(gen_gwserver, ack_sent, fun(Ref) -> some_async_test_signalling, gen_gwserver:ack_sent(Ref) end).
> In the context of testing I don't see why one would rule this possibility out except for reasons of aesthetics.
Minor fix: gen_gwserver:ack_sent(Ref) should be changed with
meck:passthrough([Ref]), like this:
fun(Ref) -> some_async_test_signalling, meck:passthrough([Ref]) end).
You are right, this would work. However, I would like an abstraction for
it, which would include both mecking and test signal catching, because
we are using it quite often.
Abstraction would need either using something other than meck, or
changing expect(Mod::atom(), Func::atom(), Expect::fun()) to accept
expect(Mod::atom(), Func::atom(), Arity::pos_int(), Expect::fun())
Expect :: function/1 which takes a list of arguments passed to mocked
Without abstraction what we could get now:
MasterPid = self(), % unsure, this might be not necessary
fun(Ref) -> MasterPid ! done, meck:passthrough([Ref]) end),
receive done -> ok end
If we don't get anything better than that, it's fine. But it's much less
gen_gwserver, ack_sent, 1),
More information about the erlang-questions