Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Testing asynchronous code
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Aman Gupta  
View profile  
(1 user)  More options Aug 9 2008, 7:04 pm
From: Aman Gupta <themastermi...@gmail.com>
Date: Sat, 9 Aug 2008 16:04:59 -0700 (PDT)
Local: Sat, Aug 9 2008 7:04 pm
Subject: [Eventmachine-talk] Testing asynchronous code
I've been experimenting with different techniques for testing async
code, and have a simple Bacon based BDD api working:

EM.describe EventMachine do
  should 'have timers' do
    start = Time.now

    EM.add_timer(0.5){
      (Time.now-start).should.be.close 0.5, 0.1
      done
    }
  end

  should 'have periodic timers' do
    num = 0
    start = Time.now

    ptimer = EM.add_periodic_timer(0.5){
      if (num += 1) == 2
        (Time.now-start).should.be.close 1.0, 0.1
        EM.cancel_timer ptimer
        done
      end
    }
  end
end

To move onto the next 'should' requirement in the spec, you must
explicitly call 'done' (or 'resume'). This means each 'should' will
effectively wait until all callbacks have been triggered and
associated assertions have been made, making it much easier to test
asynchronous code.

To achieve this, EM.describe wraps the block in a Fiber (with a simple
Thread based compatibility layer for Fibers on 1.8: http://gist.github.com/4631),
and calls Fiber.yield at the end of each 'should'. When you call
'done', it simply resumes the Fiber and continues on to the next
requirement.

The full code is available at http://gist.github.com/4708

  Aman
_______________________________________________
Eventmachine-talk mailing list
Eventmachine-t...@rubyforge.org
http://rubyforge.org/mailman/listinfo/eventmachine-talk


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google