One technique you can use is to run your tests inside a Thread and
stop and pause that thread while you wait for results:
th = Thread.current
msg = nil
some_async_function{ |m|
msg = m
th.wakeup
}
Thread.stop
assert_equal(m, ''something expected'')
See http://github.com/tmm1/em-spec for a wrapper which uses this
technique (and Fibers instead of Threads
if available) with bacon and rspec.
Aman
On Wed, Apr 29, 2009 at 12:46 AM, Kenneth Kalmer
<kenneth.kalmer at gmail.com> wrote:>
> Morning everyone
>
> I''ve just fired off an email to the nanite group on pretty much
the same topic [1], and realized this might be an appropriate place to ask the
same question, but in a non-nanite context...
>
> With the ever growing popularity of EM and interesting use cases, it got me
thinking on how to implement tests for evented code. I''m looking at
implementing more "evented generators" for daemon-kit [2] in the
future and they''ll need testing too.
>
> Without venturing into the IO parts of EM, how do you guys spec/test your
EM code?
>
> Thoughts crossing my mind are these:
>
> * Can you run the reactor just once, with a mock payload?
> * Do you mock the entire reactor out?
> * Starting/stopping the reactor multiple times in setup/teardown methods
> * Is it safe to run the reactor in it''s own thread during the
tests?
>
> I''m sure plenty more questions will come up, and I apologize for
dumping my mind right here with no apparent structure to my question. I guess
I''m not exactly sure where to even start looking for the answers.
>
> [1] -
http://groups.google.com/group/nanite/browse_thread/thread/a1f5d5d29bfe8834
> [2] - http://github.com/kennethkalmer/daemon-kit
>
> Best
>
> --
> Kenneth Kalmer
> kenneth.kalmer at gmail.com
> http://opensourcery.co.za
> @kennethkalmer
>
> _______________________________________________
> Eventmachine-talk mailing list
> Eventmachine-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/eventmachine-talk