Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

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

Justin Richard
Tuesday, July 14, 2009

Ask for Help

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

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

5 Comments

  1. Randy Schmidt says:

    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

  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
    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

  3. 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.

    July 16, 2009 at 4:18 pm

  4. Daniel DeLeo says:

    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

  5. Joseph Palermo says:

    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

Add New Comment Cancel reply

Your email address will not be published.

Justin Richard

Justin Richard
San Francisco

Recent Posts

  • [Standup][SF] 11/07/12: CSS tech talk at AirBnB tonight
  • 5/18/12 Standup – Performance without downtime please
  • 5/15/12 Standup – setting the template in database.yml
Subscribe to Justin's Feed

Author Topics

agile (6)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >