Sha256: 673b3eacff8d0de194223c725a2ec00f955d63a8ab220a50580fd2596dd5a10c

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

require 'test/unit'

$:.unshift File.join(File.dirname(__FILE__),'..','..','lib')
require 'evdispatch'

$d = Evdispatch::Loop.new
# start the event loop thread
$d.start

class TestRequests < Test::Unit::TestCase

  def test_response
    id = $d.request_http("http://127.0.0.1:4044/bytes/10")
    response = $d.response( id )
    #puts response.inspect
    #{:response_time=>0.003444, :name=>"http://127.0.0.1:4044/bytes/10", :id=>0, :body=>"CCCCCCCCCC"}
    assert_equal("http://127.0.0.1:4044/bytes/10", response[:name])
    assert_equal("CCCCCCCCCC", response[:body])
    assert_equal("HTTP/1.1 200 OK\r\nContent-Type: text/json\r\nContent-Length: 10\r\nConnection: close\r\n\r\n", response[:header])
    assert(response.keys.include?(:response_time))
    assert(response.keys.include?(:id))
  end

  def test_options_request
    id = $d.request("http://127.0.0.1:4044/redir/1", :followlocation => 1, :referer => 'pizza')
    response = $d.response( id )
    assert_match(/ 302 Moved Temporarily/,response[:header])
    assert_match(/ 200 OK/,response[:header])
  end

  def test_delayed_with_flush
    id = $d.request("http://127.0.0.1:4044/delay/0.1")
    tid = $d.request("http://127.0.0.1:4044/delay/3.0")
    res = $d.blocking_response_for( id, :timeout => 0.5 )
    res2 = $d.blocking_response_for( tid, :timeout => 0.5 )#, 1.0, 1 )
    if !res or !res2
      $d.flush # flush because we aborted before we finished, still the issue of the request is still running, but any previous responses that were delayed will be flushed
    end
    assert_not_nil res
    assert_nil res2
  end

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

# not bothering to cleanup

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
evdispatch-0.2.5 ext/revdispatch/stest.rb
evdispatch-0.2.4 ext/revdispatch/stest.rb