* EM has some tests for itself that use something like EM.run do test_some_stuff EM.stop end The tricky part is to put EM.stop _after_ everything else you need for your test to succeed has happened. * Other parts of EM use em-spec (the memcache client, for example, though the test is bundled into the library file). Same caveat as before, but with #done instead of EM.stop http://github.com/eventmachine/eventmachine/blob/master/lib/em/protocols/memcache.rb#L228-323 * I have a fork of em-spec at http://github.com/danielsdeleo/em-spec/tree/master with better rspec support. Should also be able to work with T::U and the various sugars layered on top, though I’m an rspec guy so I haven’t tried. * Mock the crap out of whatever library you’re using that needs EM. If you’re not writing your own protocol or a new library to handle a protocol, and you only need EM-capable tests because of a dependency, mock the bejesus out of it. Did this for AMQP, and was very glad I did. Use cucumber to catch anything the mocks covered up. http://github.com/danielsdeleo/moqueue/tree/master
July 14, 2009 at 6:58 pm
Joseph Palermo says:
Daniel,
It was actually AMQP that we were using and found moqueue to be perfect for our testing needs. Thanks!
Unfortunately, we are now finding that the AMQP library is not as finished as we need it to be. It we are publishing messages, and the server dies and them comes back, our publisher doesn’t seem to notice, yet only a subset of the messages that it published are actually on the queue.
One solution seems to be transactions, but they are not implemented yet.
Joseph, That’s quite interesting. Transactions are supported in the protocol classes that are autogenerated from the XML or JSON version of the spec, so I may try my hand at implementing them this weekend if I get the time.
Glad you like moqueue!
Heads up: I’m not aware of pivotal’s preferred deployment environment, but, if you didn’t know already, you need to hook into the :starting_worker_process event and do some magic when using EM with Passenger, like this:
Yeah, I see the classes for transactions in the spec.rb, they just aren’t used in the code anywhere yet.
I’m also not clear on how they would be used. With the async EM stuff, and that fact that we aren’t currently getting any failures from publish commands when the server is down, how would you know if you should commit the transaction or roll it back?
So are you saying you googled around and tried http://github.com/eventmachine/em-spec/tree/master but were still unable to test it effectively?
July 14, 2009 at 1:17 pm
At the risk of being shamelessly self-promoting…
Your options as far as I know:
* EM has some tests for itself that use something like
EM.run do
test_some_stuff
EM.stop
end
The tricky part is to put EM.stop _after_ everything else you need for your test to succeed has happened.
* Other parts of EM use em-spec (the memcache client, for example, though the test is bundled into the library file). Same caveat as before, but with #done instead of EM.stop http://github.com/eventmachine/eventmachine/blob/master/lib/em/protocols/memcache.rb#L228-323
* I have a fork of em-spec at http://github.com/danielsdeleo/em-spec/tree/master with better rspec support. Should also be able to work with T::U and the various sugars layered on top, though I’m an rspec guy so I haven’t tried.
* Mock the crap out of whatever library you’re using that needs EM. If you’re not writing your own protocol or a new library to handle a protocol, and you only need EM-capable tests because of a dependency, mock the bejesus out of it. Did this for AMQP, and was very glad I did. Use cucumber to catch anything the mocks covered up. http://github.com/danielsdeleo/moqueue/tree/master
July 14, 2009 at 6:58 pm
Daniel,
It was actually AMQP that we were using and found moqueue to be perfect for our testing needs. Thanks!
Unfortunately, we are now finding that the AMQP library is not as finished as we need it to be. It we are publishing messages, and the server dies and them comes back, our publisher doesn’t seem to notice, yet only a subset of the messages that it published are actually on the queue.
One solution seems to be transactions, but they are not implemented yet.
July 16, 2009 at 4:18 pm
Joseph,
That’s quite interesting. Transactions are supported in the protocol classes that are autogenerated from the XML or JSON version of the spec, so I may try my hand at implementing them this weekend if I get the time.
Glad you like moqueue!
Heads up: I’m not aware of pivotal’s preferred deployment environment, but, if you didn’t know already, you need to hook into the :starting_worker_process event and do some magic when using EM with Passenger, like this:
http://github.com/danielsdeleo/qusion/blob/master/lib/qusion/amqp.rb
July 17, 2009 at 6:31 am
Daniel,
Yeah, I see the classes for transactions in the spec.rb, they just aren’t used in the code anywhere yet.
I’m also not clear on how they would be used. With the async EM stuff, and that fact that we aren’t currently getting any failures from publish commands when the server is down, how would you know if you should commit the transaction or roll it back?
July 20, 2009 at 9:33 am