[erlang-questions] testing side effects of asynchronous code
Gustav Simonsson
gustav.simonsson@REDACTED
Mon Jan 2 12:02:47 CET 2012
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.
Regards,
Gustav Simonsson
Sent from my PC
----- Original Message -----
From: "Motiejus Jakštys" <desired.mta@REDACTED>
To: erlang-questions@REDACTED
Sent: Monday, 2 January, 2012 11:46:56 AM
Subject: [erlang-questions] testing side effects of asynchronous code
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:
?call_and_sleep(
gateway_api:send(Message),
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.
Thanks,
Motiejus Jakštys
_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list