Class: TestRequests

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
ext/revdispatch/stest.rb

Instance Method Summary collapse

Instance Method Details

#loopObject



16
17
18
# File 'ext/revdispatch/stest.rb', line 16

def loop
  @loop
end

#setupObject



7
8
9
10
# File 'ext/revdispatch/stest.rb', line 7

def setup
  @loop = Evdispatch::Loop.new
  @loop.start
end

#teardownObject



12
13
14
# File 'ext/revdispatch/stest.rb', line 12

def teardown
  @loop.stop
end

#test_options_requestObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'ext/revdispatch/stest.rb', line 32

def test_options_request
  id = loop.request("http://127.0.0.1:4044/redir/1",
                    :followlocation => 1,
                    :referer => 'pizza',
                    :headers => {
                      'Simple' => 'Thoughts'
                    })
  response = loop.response( id )
  assert_not_nil( response )
  assert_match(/ 302 Moved Temporarily/,response[:header])
  assert_match(/ 200 OK/,response[:header])
end

#test_postObject



59
60
61
62
63
# File 'ext/revdispatch/stest.rb', line 59

def test_post
  id = loop.request("http://127.0.0.1:4044/test_post_length", :post => "hello there world")
  res = loop.blocking_response_for( id )
  assert_not_nil res
end

#test_redir_with_streamObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'ext/revdispatch/stest.rb', line 45

def test_redir_with_stream
  stream = loop.request("http://127.0.0.1:4044/redir/2", :followlocation => 1, :stream => true )
  res = stream.read
  until res == 0
    res = stream.read
  end
  assert_equal( 0, res )
  assert_equal( "C"*10, stream.body )
  headers = stream.headers
  assert_match( "Content-Length: 10", headers )
  assert_match( "Content-Type: text/json", headers )
  assert_match( "HTTP/1.1 200 OK", headers )
end

#test_responseObject



20
21
22
23
24
25
26
27
28
29
30
# File 'ext/revdispatch/stest.rb', line 20

def test_response
  id = loop.request_http("http://127.0.0.1:4044/bytes/10")
  response = loop.response( id )
  assert_equal("http://127.0.0.1:4044/bytes/10", response[:name])
  assert_equal("CCCCCCCCCC", response[:body])
  assert_match(/Content-Type: text\/json/, response[:header])
  assert_match(/HTTP\/1.1 200 OK/, response[:header])
  assert_match(/Content-Length: 10/, response[:header])
  assert(response.keys.include?(:response_time))
  assert(response.keys.include?(:id))
end

#test_streamingObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'ext/revdispatch/stest.rb', line 65

def test_streaming
  count = 10000
  stream = loop.request("http://127.0.0.1:4044/bytes/#{count}", :stream => true )
  res = stream.read
  until res == 0
    res = stream.read
  end
  assert_equal( 0, res )
  assert_equal( "C"*count, stream.body )
  headers = stream.headers
  assert_match( "Content-Length: #{count}", headers )
  assert_match( "Content-Type: text/json", headers )
  assert_match( "HTTP/1.1 200 OK", headers )
end