[erlang-questions] testing side effects of asynchronous code
Mon Jan 2 18:57:31 CET 2012
Hi - just throwing this out there.
I started thinking about this too and wanted some kind of lib for
side-effect testing and got only as far as whipping up some basic
I didn't have too much time back then and it was mostly a proof of concept
2012/1/2 Motiejus Jakštys <>:
> Hi List,
> Let's say I am testing side effects of this asynchronous function:
> gateway_api:send(Message) -> reference()
> It does some asynchronous processing and produces side effects. After
> processing completes, gen_gwserver:ack_sent is invoked, like this:
> gen_gwserver:ack_sent(Ref :: reference()) -> ok.
> The question is: how can I know that the function ack_sent has been
> called? Then I know that asynchronous work has been completed, so I can
> start validating the side effects.
> An imaginary API in a test case, which blocks until
> gen_gwserver:ack_sent/1 has been called:
> gen_gwserver, ack_sent, 1
> Some options that we ruled out:
> * timer:sleep(some random value)
> * making internal gateway_api:ack(Reference) calls (inconvenient, since
> necessary only for testing)
> * meck:passthrough looked promising, but the problem is it doesn't
> return, so it cannot be implemented using meck cleanly.
> Motiejus Jakštys
> erlang-questions mailing list
More information about the erlang-questions