$:.unshift File.join(File.dirname(__FILE__),'..','..','lib') require 'evdispatch' require 'test/unit' $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") tid = $d.request("http://127.0.0.1:4044/delay/3") res = $d.response( id, 1.0, 1 ) res2 = $d.response( tid, 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 puts res.inspect puts res2.inspect end end # not bothering to cleanup