Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Standup 7/14/2009: How to test your code that uses Event Machine?

Ask for Help

“How have others effectively tested their code that uses Event Machine?”

  1. So are you saying you googled around and tried but were still unable to test it effectively?

  2. Daniel DeLeo says:

    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 do
    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
    * I have a fork of em-spec at 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.

  3. Joseph Palermo says:


    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.

  4. Daniel DeLeo says:

    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:

  5. Joseph Palermo says:


    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?

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *