File: pipelining_spec.rb

package info (click to toggle)
ruby-em-http-request 1.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 628 kB
  • ctags: 243
  • sloc: ruby: 3,478; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,613 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'helper'

requires_connection do

  describe EventMachine::HttpRequest do

    it "should perform successful pipelined GETs" do
      EventMachine.run do

        # Mongrel doesn't support pipelined requests - bah!
        conn = EventMachine::HttpRequest.new('http://www.igvita.com/')

        pipe1 = conn.get :keepalive => true
        pipe2 = conn.get :path => '/archives/', :keepalive => true

        processed = 0
        stop = proc { EM.stop if processed == 2}

        pipe1.errback { failed(conn) }
        pipe1.callback {
          processed += 1
          pipe1.response_header.status.should == 200
          stop.call
        }

        pipe2.errback { failed(conn) }
        pipe2.callback {
          processed += 1
          pipe2.response_header.status.should == 200
          pipe2.response.should match(/html/i)
          stop.call
        }

      end
    end

    it "should perform successful pipelined HEAD requests" do
      EventMachine.run do
        conn = EventMachine::HttpRequest.new('http://www.igvita.com/')

        pipe1 = conn.head :keepalive => true
        pipe2 = conn.head :path => '/archives/', :keepalive => true

        processed = 0
        stop = proc { EM.stop if processed == 2}

        pipe1.errback { failed(conn) }
        pipe1.callback {
          processed += 1
          pipe1.response_header.status.should == 200
          stop.call
        }

        pipe2.errback { failed(conn) }
        pipe2.callback {
          processed += 1
          pipe2.response_header.status.should == 200
          stop.call
        }

      end

    end
  end

end