Class: TestHttpClient2

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb

Defined Under Namespace

Classes: TestServer

Constant Summary collapse

Localhost =
"127.0.0.1"
Localport =
9801

Instance Method Summary collapse

Instance Method Details

#_test_get_multipleObject

Not a pipelined request because we wait for one response before we request the next. XXX this test is broken because it sends the second request to the first connection XXX right before the connection closes



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb', line 96

def _test_get_multiple
  content = nil
  EM.run {
    http = EM::P::HttpClient2.connect "google.com", 80
    d = http.get "/"
    d.callback {
      e = http.get "/"
      e.callback {
        content = e.content
        EM.stop
      }
    }
  }
  assert(content)
end

#setupObject



35
36
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb', line 35

def setup
end

#teardownObject



38
39
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb', line 38

def teardown
end

#test_authheaderObject



131
132
133
134
135
136
137
138
139
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb', line 131

def test_authheader
  EM.run {
    EM.start_server Localhost, Localport, TestServer
    http = EM::P::HttpClient2.connect Localhost, 18842
    d = http.get :url=>"/", :authorization=>"Basic xxx"
    d.callback {EM.stop}
    d.errback {EM.stop}
  }
end

#test_bad_portObject



60
61
62
63
64
65
66
67
68
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb', line 60

def test_bad_port
  EM.run {
    EM.start_server Localhost, Localport, TestServer
    assert_raises( ArgumentError ) {
      EM::P::HttpClient2.connect Localhost, "xxx"
    }
    EM.stop
  }
end

#test_bad_serverObject



70
71
72
73
74
75
76
77
78
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb', line 70

def test_bad_server
  err = nil
  EM.run {
    http = EM::P::HttpClient2.connect Localhost, 9999
    d = http.get "/"
    d.errback { err = true; d.internal_error; EM.stop }
  }
  assert(err)
end

#test_connectObject

#connect returns an object which has made a connection to an HTTP server and exposes methods for making HTTP requests on that connection. #connect can take either a pair of parameters (a host and a port), or a single parameter which is a Hash.



50
51
52
53
54
55
56
57
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb', line 50

def test_connect
  EM.run {
    EM.start_server Localhost, Localport, TestServer
    http1 = EM::P::HttpClient2.connect Localhost, Localport
    http2 = EM::P::HttpClient2.connect( :host=>Localhost, :port=>Localport )
    EM.stop
  }
end

#test_getObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb', line 80

def test_get
  content = nil
  EM.run {
    http = EM::P::HttpClient2.connect "google.com", 80
    d = http.get "/"
    d.callback {
      content = d.content
      EM.stop
    }
  }
  assert(content)
end

#test_get_pipelineObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb', line 112

def test_get_pipeline
  headers, headers2 = nil, nil
  EM.run {
    http = EM::P::HttpClient2.connect "google.com", 80
    d = http.get("/")
    d.callback {
      headers = d.headers
    }
    e = http.get("/")
    e.callback {
      headers2 = e.headers
    }
    EM::Timer.new(1) {EM.stop}
  }
  assert(headers)
  assert(headers2)
end

#test_https_getObject



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb', line 141

def test_https_get
  d = nil
  EM.run {
    http = EM::P::HttpClient2.connect :host => 'www.amazon.com', :port => 443, :ssl => true
    d = http.get "/"
    d.callback {
      EM.stop
    }
  }
  assert_equal(200, d.status)
end