Sha256: 6f4979e46cfbe34e78a8e90d7324bb47079ef3e985c3e3891e8d8a2521744149

Contents?: true

Size: 910 Bytes

Versions: 8

Compression:

Stored size: 910 Bytes

Contents

require 'spec_helper'

class Interleaving < Goliath::API
  use Goliath::Rack::Params

  def response(env)
    delay = env.params['delay']
    EM::Synchrony.sleep(delay.to_f)

    [200, {}, delay]
  end
end

describe 'HTTP Pipelining support' do
  it 'serves multiple requests via single connection' do
    with_api(Interleaving, :port => 9901) do
      start = Time.now.to_f
      res = []

      conn = EM::HttpRequest.new('http://localhost:9901')
      r1 = conn.aget :query => {:delay => 0.3}, :keepalive => true
      r2 = conn.aget :query => {:delay => 0.2}

      r1.errback { fail }
      r1.callback do |c|
        res << c.response
        c.response.should match('0.3')
      end

      r2.errback { fail }
      r2.callback do |c|
        res << c.response

        res.should == ['0.3', '0.2']
        (Time.now.to_f - start).should be_within(0.1).of(0.3)

        stop
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
goliath-1.0.5 spec/integration/pipelining_spec.rb
goliath-1.0.4 spec/integration/pipelining_spec.rb
goliath-1.0.3 spec/integration/pipelining_spec.rb
goliath-1.0.2 spec/integration/pipelining_spec.rb
goliath-1.0.1 spec/integration/pipelining_spec.rb
goliath-1.0.0 spec/integration/pipelining_spec.rb
goliath-1.0.0.beta.1 spec/integration/pipelining_spec.rb
goliath-0.9.4 spec/integration/pipelining_spec.rb