Sha256: 88537c12c6cd1d5c8cb5d8c40c584d737b5b1f26b8307c33c36e2c101cb7678f

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

require 'helper'
require 'stallion'

describe EventMachine::MultiRequest do

  it "should submit multiple requests in parallel and return once all of them are complete" do
    EventMachine.run {

      # create an instance of multi-request handler, and the requests themselves
      multi = EventMachine::MultiRequest.new

      # add multiple requests to the multi-handler
      multi.add(EventMachine::HttpRequest.new('http://127.0.0.1:8090/').get(:query => {:q => 'test'}))
      multi.add(EventMachine::HttpRequest.new('http://127.0.0.1:8090/').get)

      multi.callback  {
        multi.responses[:succeeded].size.should == 2
        multi.responses[:succeeded][0].response.should match(/test|Hello/)
        multi.responses[:succeeded][1].response.should match(/test|Hello/)

        EventMachine.stop
      }
    }
  end

  it "should accept multiple open connections and return once all of them are complete" do
    EventMachine.run {
      http1 = EventMachine::HttpRequest.new('http://127.0.0.1:8090/').get(:query => {:q => 'test'})
      http2 = EventMachine::HttpRequest.new('http://127.0.0.1:8090/').get

      multi = EventMachine::MultiRequest.new([http1, http2]) do
        multi.responses[:succeeded].size.should == 2
        multi.responses[:succeeded][0].response.should match(/test|Hello/)
        multi.responses[:succeeded][1].response.should match(/test|Hello/)

        EventMachine.stop
      end
    }
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
em-http-request-1.0.0.beta.3 spec/multi_spec.rb
em-http-request-1.0.0.beta.2 spec/multi_spec.rb
em-http-request-1.0.0.beta.1 spec/multi_spec.rb