[erlang-questions] testing side effects of asynchronous code
Ahmed Omar
spawn.think@REDACTED
Tue Jan 3 10:57:02 CET 2012
of course you would call it as
call_and_sleep({gateway_api,send,[Msg]}, {gen_gwserver, ack_sent, 1}).
Also, If you need to check the Args passed to ack_sent, you can add some
MatchSpec to the trace_pattern to do that.
2012/1/3 Ahmed Omar <spawn.think@REDACTED>
> Ignas,
> The problem is not in the flags, it's just that the process can't trace
> itself.
> For example you can't do this
> erlang:trace(self(), true, [call, {tracer,self()}]).
>
> If u wanna use tracing for this, you can simply write the desired api as :
> call_and_sleep({ModC, FunC, ArgC}=_Call, {ModS,FunS,ArgS}=_SleepFor)->
> erlang:trace(all ,true, [call]),
> erlang:trace_pattern({ModS, FunS, ArgS}, true, []),
> spawn(ModC, FunC, ArgC),
> receive
> {trace, _, _, _} ->
> ok
> end.
>
> 2012/1/2 Ignas Vyšniauskas <baliulia@REDACTED>
>
>> On 2012.01.02 19:57, Gianfranco Alongi wrote:
>> > 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
>> > stuff
>> >
>> >
>> https://github.com/Gianfrancoalongi/Audit-Collector---A-real-time-version-of-Frame-Axiom/
>> >
>> > I didn't have too much time back then and it was mostly a proof of
>> concept
>> >
>> > /G
>>
>> Hmm, this is interesting, I was thinking of abusing the Erlang tracer as
>> well.
>>
>> For the question Motiejus raised, could something like this possibly work:
>>
>> erlang:trace(all, true, [call, {tracer, self()}]),
>> % I tried all of the flags: global, local and meta, all failed
>> erlang:trace_pattern({gen_gwserver, ack_sent, 1}, true, [local]),
>> gateway_api:send(Msg),
>> receive
>> {trace, _, _, _} ->
>> ok % gen_gwserver:ack_sent/1 was called, we can proceed
>> end,
>> ?assert(Something)
>>
>> I tried this, but it didn't work. Unfortunately, my understanding of
>> Erlang's trace mechanism is very poor, so I couldn't work out whether
>> it's possible to fix it somehow.
>>
>> Thanks,
>> Ignas
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
>
>
> --
> Best Regards,
> - Ahmed Omar
> http://nl.linkedin.com/in/adiaa
> Follow me on twitter
> @spawn_think <http://twitter.com/#!/spawn_think>
>
>
--
Best Regards,
- Ahmed Omar
http://nl.linkedin.com/in/adiaa
Follow me on twitter
@spawn_think <http://twitter.com/#!/spawn_think>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120103/5290c04b/attachment.htm>
More information about the erlang-questions
mailing list