From e25b558ba8d2d6812d490b365539c2a7bf219e12 Mon Sep 17 00:00:00 2001 From: Ian Ownbey Date: Sat, 22 Nov 2008 14:15:54 -0800 Subject: Added testing for rack support --- test/unit/test_ws.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/unit/test_ws.rb b/test/unit/test_ws.rb index 9de8a45..036752a 100644 --- a/test/unit/test_ws.rb +++ b/test/unit/test_ws.rb @@ -8,13 +8,14 @@ require 'test/test_helper' include Mongrel -class TestHandler < Mongrel::HttpHandler +class TestHandler attr_reader :ran_test - def process(request, response) + def call(env) @ran_test = true - response.socket.write("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nhello!\n") - end + # response.socket.write("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nhello!\n") + [200, { 'Content-Type' => 'text/plain' }, ['hello!\n']] + end end @@ -23,13 +24,13 @@ class WebServerTest < Test::Unit::TestCase def setup @valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n" @port = process_based_port - + @tester = TestHandler.new + @app = Rack::URLMap.new('/test' => @tester) redirect_test_io do # We set num_processors=1 so that we can test the reaping code - @server = HttpServer.new("127.0.0.1", @port, num_processors=1) + @server = HttpServer.new("127.0.0.1", @port, @app, :num_processors => 1) end - @tester = TestHandler.new @server.register("/test", @tester) redirect_test_io do @server.run -- cgit v1.2.3-24-ge0c7 From a59c388dd518d0b0ff85d0621d3406fcc23d6173 Mon Sep 17 00:00:00 2001 From: Ian Ownbey Date: Sat, 22 Nov 2008 17:48:36 -0800 Subject: Non working rack implementation --- test/unit/test_ws.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'test') diff --git a/test/unit/test_ws.rb b/test/unit/test_ws.rb index 036752a..7508c7f 100644 --- a/test/unit/test_ws.rb +++ b/test/unit/test_ws.rb @@ -29,11 +29,7 @@ class WebServerTest < Test::Unit::TestCase redirect_test_io do # We set num_processors=1 so that we can test the reaping code @server = HttpServer.new("127.0.0.1", @port, @app, :num_processors => 1) - end - - @server.register("/test", @tester) - redirect_test_io do - @server.run + @server.start! end end -- cgit v1.2.3-24-ge0c7 From c178815ef6496d3d2dfe83b77a0332138a4ae1ee Mon Sep 17 00:00:00 2001 From: Ian Ownbey Date: Mon, 1 Dec 2008 00:50:24 -0500 Subject: Got tests working with rack --- test/unit/test_handlers.rb | 136 ------------------------------------- test/unit/test_redirect_handler.rb | 45 ------------ test/unit/test_response.rb | 74 ++------------------ 3 files changed, 4 insertions(+), 251 deletions(-) delete mode 100644 test/unit/test_handlers.rb delete mode 100644 test/unit/test_redirect_handler.rb (limited to 'test') diff --git a/test/unit/test_handlers.rb b/test/unit/test_handlers.rb deleted file mode 100644 index 66bf010..0000000 --- a/test/unit/test_handlers.rb +++ /dev/null @@ -1,136 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'test/test_helper' - -class SimpleHandler < Mongrel::HttpHandler - def process(request, response) - response.start do |head,out| - head["Content-Type"] = "text/html" - results = "Your request:
#{request.params.to_yaml}
View the files." - out << results - end - end -end - -class DumbHandler < Mongrel::HttpHandler - def process(request, response) - response.start do |head,out| - head["Content-Type"] = "text/html" - out.write("test") - end - end -end - -def check_status(results, expecting) - results.each do |res| - assert(res.kind_of?(expecting), "Didn't get #{expecting}, got: #{res.class}") - end -end - -class HandlersTest < Test::Unit::TestCase - - def setup - @port = process_based_port - stats = Mongrel::StatisticsFilter.new(:sample_rate => 1) - - @config = Mongrel::Configurator.new :host => '127.0.0.1' do - listener :port => process_based_port do - uri "/", :handler => SimpleHandler.new - uri "/", :handler => stats - uri "/404", :handler => Mongrel::Error404Handler.new("Not found") - uri "/dumb", :handler => Mongrel::DeflateFilter.new - uri "/dumb", :handler => DumbHandler.new, :in_front => true - uri "/files", :handler => Mongrel::DirHandler.new("doc") - uri "/files_nodir", :handler => Mongrel::DirHandler.new("doc", listing_allowed=false, index_html="none") - uri "/status", :handler => Mongrel::StatusHandler.new(:stats_filter => stats) - uri "/relative", :handler => Mongrel::DirHandler.new(nil, listing_allowed=false, index_html="none") - end - end - - unless windows? - File.open('/tmp/testfile', 'w') do - # Do nothing - end - end - - @config.run - end - - def teardown - @config.stop(false, true) - File.delete '/tmp/testfile' unless windows? - end - - def test_registration_exception_is_not_lost - assert_raises(Mongrel::URIClassifier::RegistrationError) do - @config = Mongrel::Configurator.new do - listener do - uri "bogus", :handler => SimpleHandler.new - end - end - end - end - - def test_more_web_server - res = hit([ "http://localhost:#{@port}/test", - "http://localhost:#{@port}/dumb", - "http://localhost:#{@port}/404", - "http://localhost:#{@port}/files/rdoc/index.html", - "http://localhost:#{@port}/files/rdoc/nothere.html", - "http://localhost:#{@port}/files/rdoc/", - "http://localhost:#{@port}/files_nodir/rdoc/", - "http://localhost:#{@port}/status", - ]) - check_status res, String - end - - def test_nil_dirhandler - return if windows? - # Camping uses this internally - handler = Mongrel::DirHandler.new(nil, false) - assert handler.can_serve("/tmp/testfile") - # Not a bug! A nil @file parameter is the only circumstance under which - # we are allowed to serve any existing file - assert handler.can_serve("../../../../../../../../../../tmp/testfile") - end - - def test_non_nil_dirhandler_is_not_vulnerable_to_path_traversal - # The famous security bug of Mongrel 1.1.2 - handler = Mongrel::DirHandler.new("/doc", false) - assert_nil handler.can_serve("/tmp/testfile") - assert_nil handler.can_serve("../../../../../../../../../../tmp/testfile") - end - - def test_deflate - Net::HTTP.start("localhost", @port) do |h| - # Test that no accept-encoding returns a non-deflated response - req = h.get("/dumb") - assert( - !req['Content-Encoding'] || - !req['Content-Encoding'].include?('deflate')) - assert_equal "test", req.body - - req = h.get("/dumb", {"Accept-Encoding" => "deflate"}) - # -MAX_WBITS stops zlib from looking for a zlib header - inflater = Zlib::Inflate.new(-Zlib::MAX_WBITS) - assert req['Content-Encoding'].include?('deflate') - assert_equal "test", inflater.inflate(req.body) - end - end - - # TODO: find out why this fails on win32 but nowhere else - #def test_posting_fails_dirhandler - # req = Net::HTTP::Post.new("http://localhost:#{@port}/files/rdoc/") - # req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';') - # res = hit [["http://localhost:#{@port}/files/rdoc/",req]] - # check_status res, Net::HTTPNotFound - #end - - def test_unregister - @config.listeners["127.0.0.1:#{@port}"].unregister("/") - end -end diff --git a/test/unit/test_redirect_handler.rb b/test/unit/test_redirect_handler.rb deleted file mode 100644 index e990427..0000000 --- a/test/unit/test_redirect_handler.rb +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'test/test_helper' - -class RedirectHandlerTest < Test::Unit::TestCase - - def setup - @port = process_based_port - redirect_test_io do - @server = Mongrel::HttpServer.new('127.0.0.1', @port) - end - @server.run - @client = Net::HTTP.new('127.0.0.1', @port) - end - - def teardown - @server.stop(true) - end - - def test_simple_redirect - tester = Mongrel::RedirectHandler.new('/yo') - @server.register("/test", tester) - - sleep(1) - res = @client.request_get('/test') - assert res != nil, "Didn't get a response" - assert_equal ['/yo'], res.get_fields('Location') - end - - def test_rewrite - tester = Mongrel::RedirectHandler.new(/(\w+)/, '+\1+') - @server.register("/test", tester) - - sleep(1) - res = @client.request_get('/test/something') - assert_equal ['/+test+/+something+'], res.get_fields('Location') - end - -end - - diff --git a/test/unit/test_response.rb b/test/unit/test_response.rb index b49c9df..769b0d6 100644 --- a/test/unit/test_response.rb +++ b/test/unit/test_response.rb @@ -12,11 +12,7 @@ class ResponseTest < Test::Unit::TestCase def test_response_headers out = StringIO.new - resp = HttpResponse.new(out) - resp.status = 200 - resp.header["Accept"] = "text/plain" - resp.header["X-Whatever"] = "stuff" - resp.body.write("test") + resp = HttpResponse.new(out,[200, {"X-Whatever" => "stuff"}, ["cool"]]) resp.finished assert out.length > 0, "output didn't have data" @@ -24,56 +20,7 @@ class ResponseTest < Test::Unit::TestCase def test_response_200 io = StringIO.new - resp = HttpResponse.new(io) - resp.start do |head,out| - head["Accept"] = "text/plain" - out.write("tested") - out.write("hello!") - end - - resp.finished - assert io.length > 0, "output didn't have data" - end - - def test_response_duplicate_header_squash - io = StringIO.new - resp = HttpResponse.new(io) - resp.start do |head,out| - head["Content-Length"] = 30 - head["Content-Length"] = 0 - end - - resp.finished - - assert_equal io.length, 95, "too much output" - end - - - def test_response_some_duplicates_allowed - allowed_duplicates = ["Set-Cookie", "Set-Cookie2", "Warning", "WWW-Authenticate"] - io = StringIO.new - resp = HttpResponse.new(io) - resp.start do |head,out| - allowed_duplicates.each do |dup| - 10.times do |i| - head[dup] = i - end - end - end - - resp.finished - - assert_equal io.length, 734, "wrong amount of output" - end - - def test_response_404 - io = StringIO.new - - resp = HttpResponse.new(io) - resp.start(404) do |head,out| - head['Accept'] = "text/plain" - out.write("NOT FOUND") - end + resp = HttpResponse.new(io, [200, {}, []]) resp.finished assert io.length > 0, "output didn't have data" @@ -101,24 +48,11 @@ class ResponseTest < Test::Unit::TestCase assert io.read[-contents.length..-1] == contents, "output doesn't end with file payload" end - def test_response_with_custom_reason - reason = "You made a bad request" - io = StringIO.new - resp = HttpResponse.new(io) - resp.start(400, false, reason) { |head,out| } - resp.finished - - io.rewind - assert_match(/.* #{reason}$/, io.readline.chomp, "wrong custom reason phrase") - end - def test_response_with_default_reason code = 400 io = StringIO.new - resp = HttpResponse.new(io) - resp.start(code) { |head,out| } - resp.finished - + resp = HttpResponse.new(io, [code, {}, []]) + resp.start io.rewind assert_match(/.* #{HTTP_STATUS_CODES[code]}$/, io.readline.chomp, "wrong default reason phrase") end -- cgit v1.2.3-24-ge0c7 From 2482c33a3b616ad62d0b564c0d7224dd8432ffdf Mon Sep 17 00:00:00 2001 From: Ian Ownbey Date: Mon, 1 Dec 2008 00:57:05 -0500 Subject: Removed configurator, replaced by Racks UrlMap --- test/unit/test_configurator.rb | 88 ------------------------------------------ 1 file changed, 88 deletions(-) delete mode 100644 test/unit/test_configurator.rb (limited to 'test') diff --git a/test/unit/test_configurator.rb b/test/unit/test_configurator.rb deleted file mode 100644 index dc9713a..0000000 --- a/test/unit/test_configurator.rb +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'test/test_helper' - -$test_plugin_fired = 0 - -class TestPlugin < GemPlugin::Plugin "/handlers" - include Mongrel::HttpHandlerPlugin - - def process(request, response) - $test_plugin_fired += 1 - end -end - - -class Sentinel < GemPlugin::Plugin "/handlers" - include Mongrel::HttpHandlerPlugin - - def process(request, response) - raise "This Sentinel plugin shouldn't run." - end -end - - -class ConfiguratorTest < Test::Unit::TestCase - - def test_base_handler_config - @port = process_based_port - @config = nil - - redirect_test_io do - @config = Mongrel::Configurator.new :host => "localhost" do - listener :port => process_based_port do - # 2 in front should run, but the sentinel shouldn't since dirhandler processes the request - uri "/", :handler => plugin("/handlers/testplugin") - uri "/", :handler => plugin("/handlers/testplugin") - uri "/", :handler => Mongrel::DirHandler.new(".") - uri "/", :handler => plugin("/handlers/testplugin") - - uri "/test", :handler => plugin("/handlers/testplugin") - uri "/test", :handler => plugin("/handlers/testplugin") - uri "/test", :handler => Mongrel::DirHandler.new(".") - uri "/test", :handler => plugin("/handlers/testplugin") - - debug "/" - setup_signals - - run_config(HERE + "/mongrel.conf") - load_mime_map(HERE + "/mime.yaml") - - run - end - end - end - - # pp @config.listeners.values.first.classifier.routes - - @config.listeners.each do |host,listener| - assert listener.classifier.uris.length == 3, "Wrong number of registered URIs" - assert listener.classifier.uris.include?("/"), "/ not registered" - assert listener.classifier.uris.include?("/test"), "/test not registered" - end - - res = Net::HTTP.get(URI.parse("http://localhost:#{@port}/test")) - assert res != nil, "Didn't get a response" - assert $test_plugin_fired == 3, "Test filter plugin didn't run 3 times." - - redirect_test_io do - res = Net::HTTP.get(URI.parse("http://localhost:#{@port}/")) - - assert res != nil, "Didn't get a response" - assert $test_plugin_fired == 6, "Test filter plugin didn't run 6 times." - end - - redirect_test_io do - @config.stop(false, true) - end - - assert_raise Errno::EBADF, Errno::ECONNREFUSED do - res = Net::HTTP.get(URI.parse("http://localhost:#{@port}/")) - end - end - -end -- cgit v1.2.3-24-ge0c7 From d2dcbb98ae7c3963c0c658c196644095ccaec1ca Mon Sep 17 00:00:00 2001 From: Ian Ownbey Date: Mon, 1 Dec 2008 03:45:02 -0500 Subject: Got rid of handlers and test_conditional, now people just use rack --- test/unit/test_conditional.rb | 107 ------------------------------------------ 1 file changed, 107 deletions(-) delete mode 100644 test/unit/test_conditional.rb (limited to 'test') diff --git a/test/unit/test_conditional.rb b/test/unit/test_conditional.rb deleted file mode 100644 index 64517db..0000000 --- a/test/unit/test_conditional.rb +++ /dev/null @@ -1,107 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'test/test_helper' - -include Mongrel - -class ConditionalResponseTest < Test::Unit::TestCase - def setup - @server = HttpServer.new('127.0.0.1', process_based_port) - @server.register('/', Mongrel::DirHandler.new('.')) - @server.run - - @http = Net::HTTP.new(@server.host, @server.port) - - # get the ETag and Last-Modified headers - @path = '/README' - res = @http.start { |http| http.get(@path) } - assert_not_nil @etag = res['ETag'] - assert_not_nil @last_modified = res['Last-Modified'] - assert_not_nil @content_length = res['Content-Length'] - end - - def teardown - @server.stop(true) - end - - # status should be 304 Not Modified when If-None-Match is the matching ETag - def test_not_modified_via_if_none_match - assert_status_for_get_and_head Net::HTTPNotModified, 'If-None-Match' => @etag - end - - # status should be 304 Not Modified when If-Modified-Since is the matching Last-Modified date - def test_not_modified_via_if_modified_since - assert_status_for_get_and_head Net::HTTPNotModified, 'If-Modified-Since' => @last_modified - end - - # status should be 304 Not Modified when If-None-Match is the matching ETag - # and If-Modified-Since is the matching Last-Modified date - def test_not_modified_via_if_none_match_and_if_modified_since - assert_status_for_get_and_head Net::HTTPNotModified, 'If-None-Match' => @etag, 'If-Modified-Since' => @last_modified - end - - # status should be 200 OK when If-None-Match is invalid - def test_invalid_if_none_match - assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => 'invalid' - assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => 'invalid', 'If-Modified-Since' => @last_modified - end - - # status should be 200 OK when If-Modified-Since is invalid - def test_invalid_if_modified_since - assert_status_for_get_and_head Net::HTTPOK, 'If-Modified-Since' => 'invalid' - assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => @etag, 'If-Modified-Since' => 'invalid' - end - - # status should be 304 Not Modified when If-Modified-Since is greater than the Last-Modified header, but less than the system time - def test_if_modified_since_greater_than_last_modified - sleep 2 - last_modified_plus_1 = (Time.httpdate(@last_modified) + 1).httpdate - assert_status_for_get_and_head Net::HTTPNotModified, 'If-Modified-Since' => last_modified_plus_1 - assert_status_for_get_and_head Net::HTTPNotModified, 'If-None-Match' => @etag, 'If-Modified-Since' => last_modified_plus_1 - end - - # status should be 200 OK when If-Modified-Since is less than the Last-Modified header - def test_if_modified_since_less_than_last_modified - last_modified_minus_1 = (Time.httpdate(@last_modified) - 1).httpdate - assert_status_for_get_and_head Net::HTTPOK, 'If-Modified-Since' => last_modified_minus_1 - assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => @etag, 'If-Modified-Since' => last_modified_minus_1 - end - - # status should be 200 OK when If-Modified-Since is a date in the future - def test_future_if_modified_since - the_future = Time.at(2**31-1).httpdate - assert_status_for_get_and_head Net::HTTPOK, 'If-Modified-Since' => the_future - assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => @etag, 'If-Modified-Since' => the_future - end - - # status should be 200 OK when If-None-Match is a wildcard - def test_wildcard_match - assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => '*' - assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => '*', 'If-Modified-Since' => @last_modified - end - - private - - # assert the response status is correct for GET and HEAD - def assert_status_for_get_and_head(response_class, headers = {}) - %w{ get head }.each do |method| - res = @http.send(method, @path, headers) - assert_kind_of response_class, res - assert_equal @etag, res['ETag'] - case response_class.to_s - when 'Net::HTTPNotModified' then - assert_nil res['Last-Modified'] - assert_nil res['Content-Length'] - when 'Net::HTTPOK' then - assert_equal @last_modified, res['Last-Modified'] - assert_equal @content_length, res['Content-Length'] - else - fail "Incorrect response class: #{response_class}" - end - end - end -end -- cgit v1.2.3-24-ge0c7 From 384e40051b90087323ad764712e94a3bb86bc49b Mon Sep 17 00:00:00 2001 From: Ian Ownbey Date: Mon, 1 Dec 2008 03:45:43 -0500 Subject: Got rid of send_file test, moved to rack --- test/unit/test_response.rb | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'test') diff --git a/test/unit/test_response.rb b/test/unit/test_response.rb index 769b0d6..f0efdb1 100644 --- a/test/unit/test_response.rb +++ b/test/unit/test_response.rb @@ -26,28 +26,6 @@ class ResponseTest < Test::Unit::TestCase assert io.length > 0, "output didn't have data" end - def test_response_file - contents = "PLAIN TEXT\r\nCONTENTS\r\n" - require 'tempfile' - tmpf = Tempfile.new("test_response_file") - tmpf.binmode - tmpf.write(contents) - tmpf.rewind - - io = StringIO.new - resp = HttpResponse.new(io) - resp.start(200) do |head,out| - head['Content-Type'] = 'text/plain' - resp.send_header - resp.send_file(tmpf.path) - end - io.rewind - tmpf.close - - assert io.length > 0, "output didn't have data" - assert io.read[-contents.length..-1] == contents, "output doesn't end with file payload" - end - def test_response_with_default_reason code = 400 io = StringIO.new @@ -56,6 +34,5 @@ class ResponseTest < Test::Unit::TestCase io.rewind assert_match(/.* #{HTTP_STATUS_CODES[code]}$/, io.readline.chomp, "wrong default reason phrase") end - end -- cgit v1.2.3-24-ge0c7 From 9c82be1259a951a8e34459b63f3ad27ea9b95a30 Mon Sep 17 00:00:00 2001 From: Ian Ownbey Date: Mon, 1 Dec 2008 15:52:42 -0800 Subject: Removed request_progress, make it a middlewear or something --- test/unit/test_request_progress.rb | 100 ------------------------------------- 1 file changed, 100 deletions(-) delete mode 100644 test/unit/test_request_progress.rb (limited to 'test') diff --git a/test/unit/test_request_progress.rb b/test/unit/test_request_progress.rb deleted file mode 100644 index a100426..0000000 --- a/test/unit/test_request_progress.rb +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'test/test_helper' - -class UploadBeginHandler < Mongrel::HttpHandler - attr_reader :request_began, :request_progressed, :request_processed - - def initialize - @request_notify = true - end - - def reset - @request_began = false - @request_progressed = false - @request_processed = false - end - - def request_begins(params) - @request_began = true - end - - def request_progress(params,len,total) - @request_progressed = true - end - - def process(request, response) - @request_processed = true - response.start do |head,body| - body.write("test") - end - end - -end - -class RequestProgressTest < Test::Unit::TestCase - def setup - @port = process_based_port - redirect_test_io do - @server = Mongrel::HttpServer.new("127.0.0.1", @port) - end - @handler = UploadBeginHandler.new - @server.register("/upload", @handler) - @server.run - end - - def teardown - @server.stop(true) - end - - def test_begin_end_progress - Net::HTTP.get("localhost", "/upload", @port) - assert @handler.request_began - assert @handler.request_progressed - assert @handler.request_processed - end - - def call_and_assert_handlers_in_turn(handlers) - # reset all handlers - handlers.each { |h| h.reset } - - # make the call - Net::HTTP.get("localhost", "/upload", @port) - - # assert that each one was fired - handlers.each { |h| - assert h.request_began && h.request_progressed && h.request_processed, - "Callbacks NOT fired for #{h}" - } - end - - def test_more_than_one_begin_end_progress - handlers = [@handler] - - second = UploadBeginHandler.new - @server.register("/upload", second) - handlers << second - call_and_assert_handlers_in_turn(handlers) - - # check three handlers - third = UploadBeginHandler.new - @server.register("/upload", third) - handlers << third - call_and_assert_handlers_in_turn(handlers) - - # remove handlers to make sure they've all gone away - @server.unregister("/upload") - handlers.each { |h| h.reset } - Net::HTTP.get("localhost", "/upload", @port) - handlers.each { |h| - assert !h.request_began && !h.request_progressed && !h.request_processed - } - - # re-register upload to the state before this test - @server.register("/upload", @handler) - end -end -- cgit v1.2.3-24-ge0c7 From 0d838c607c0c709e5190b24aff116306f4d02255 Mon Sep 17 00:00:00 2001 From: Ian Ownbey Date: Thu, 4 Dec 2008 15:36:59 -0800 Subject: Removed uri_classifier, now we just use racks --- test/unit/test_uriclassifier.rb | 261 ---------------------------------------- 1 file changed, 261 deletions(-) delete mode 100644 test/unit/test_uriclassifier.rb (limited to 'test') diff --git a/test/unit/test_uriclassifier.rb b/test/unit/test_uriclassifier.rb deleted file mode 100644 index a438065..0000000 --- a/test/unit/test_uriclassifier.rb +++ /dev/null @@ -1,261 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'test/test_helper' - -include Mongrel - -class URIClassifierTest < Test::Unit::TestCase - - def test_uri_finding - uri_classifier = URIClassifier.new - uri_classifier.register("/test", 1) - - script_name, path_info, value = uri_classifier.resolve("/test") - assert_equal 1, value - assert_equal "/test", script_name - end - - def test_root_handler_only - uri_classifier = URIClassifier.new - uri_classifier.register("/", 1) - - script_name, path_info, value = uri_classifier.resolve("/test") - assert_equal 1, value - assert_equal "/", script_name - assert_equal "/test", path_info - end - - def test_uri_prefix_ops - test = "/pre/fix/test" - prefix = "/pre" - - uri_classifier = URIClassifier.new - uri_classifier.register(prefix,1) - - script_name, path_info, value = uri_classifier.resolve(prefix) - script_name, path_info, value = uri_classifier.resolve(test) - assert_equal 1, value - assert_equal prefix, script_name - assert_equal test[script_name.length .. -1], path_info - - assert uri_classifier.inspect - assert_equal prefix, uri_classifier.uris[0] - end - - def test_not_finding - test = "/cant/find/me" - uri_classifier = URIClassifier.new - uri_classifier.register(test, 1) - - script_name, path_info, value = uri_classifier.resolve("/nope/not/here") - assert_nil script_name - assert_nil path_info - assert_nil value - end - - def test_exceptions - uri_classifier = URIClassifier.new - - uri_classifier.register("/test", 1) - - failed = false - begin - uri_classifier.register("/test", 1) - rescue => e - failed = true - end - - assert failed - - failed = false - begin - uri_classifier.register("", 1) - rescue => e - failed = true - end - - assert failed - end - - - def test_register_unregister - uri_classifier = URIClassifier.new - - 100.times do - uri_classifier.register("/stuff", 1) - value = uri_classifier.unregister("/stuff") - assert_equal 1, value - end - - uri_classifier.register("/things",1) - script_name, path_info, value = uri_classifier.resolve("/things") - assert_equal 1, value - - uri_classifier.unregister("/things") - script_name, path_info, value = uri_classifier.resolve("/things") - assert_nil value - - end - - - def test_uri_branching - uri_classifier = URIClassifier.new - uri_classifier.register("/test", 1) - uri_classifier.register("/test/this",2) - - script_name, path_info, handler = uri_classifier.resolve("/test") - script_name, path_info, handler = uri_classifier.resolve("/test/that") - assert_equal "/test", script_name, "failed to properly find script off branch portion of uri" - assert_equal "/that", path_info - assert_equal 1, handler, "wrong result for branching uri" - end - - def test_all_prefixing - tests = ["/test","/test/that","/test/this"] - uri = "/test/this/that" - uri_classifier = URIClassifier.new - - current = "" - uri.each_byte do |c| - current << c.chr - uri_classifier.register(current, c) - end - - - # Try to resolve everything with no asserts as a fuzzing - tests.each do |prefix| - current = "" - prefix.each_byte do |c| - current << c.chr - script_name, path_info, handler = uri_classifier.resolve(current) - assert script_name - assert path_info - assert handler - end - end - - # Assert that we find stuff - tests.each do |t| - script_name, path_info, handler = uri_classifier.resolve(t) - assert handler - end - - # Assert we don't find stuff - script_name, path_info, handler = uri_classifier.resolve("chicken") - assert_nil handler - assert_nil script_name - assert_nil path_info - end - - - # Verifies that a root mounted ("/") handler resolves - # such that path info matches the original URI. - # This is needed to accommodate real usage of handlers. - def test_root_mounted - uri_classifier = URIClassifier.new - root = "/" - path = "/this/is/a/test" - - uri_classifier.register(root, 1) - - script_name, path_info, handler = uri_classifier.resolve(root) - assert_equal 1, handler - assert_equal root, path_info - assert_equal root, script_name - - script_name, path_info, handler = uri_classifier.resolve(path) - assert_equal path, path_info - assert_equal root, script_name - assert_equal 1, handler - end - - # Verifies that a root mounted ("/") handler - # is the default point, doesn't matter the order we use - # to register the URIs - def test_classifier_order - tests = ["/before", "/way_past"] - root = "/" - path = "/path" - - uri_classifier = URIClassifier.new - uri_classifier.register(path, 1) - uri_classifier.register(root, 2) - - tests.each do |uri| - script_name, path_info, handler = uri_classifier.resolve(uri) - assert_equal root, script_name, "#{uri} did not resolve to #{root}" - assert_equal uri, path_info - assert_equal 2, handler - end - end - - if ENV['BENCHMARK'] - # Eventually we will have a suite of benchmarks instead of lamely installing a test - - def test_benchmark - - # This URI set should favor a TST. Both versions increase linearly until you hit 14 - # URIs, then the TST flattens out. - @uris = %w( - / - /dag /dig /digbark /dog /dogbark /dog/bark /dug /dugbarking /puppy - /c /cat /cat/tree /cat/tree/mulberry /cats /cot /cot/tree/mulberry /kitty /kittycat -# /eag /eig /eigbark /eog /eogbark /eog/bark /eug /eugbarking /iuppy -# /f /fat /fat/tree /fat/tree/mulberry /fats /fot /fot/tree/mulberry /jitty /jittyfat -# /gag /gig /gigbark /gog /gogbark /gog/bark /gug /gugbarking /kuppy -# /h /hat /hat/tree /hat/tree/mulberry /hats /hot /hot/tree/mulberry /litty /littyhat -# /ceag /ceig /ceigbark /ceog /ceogbark /ceog/cbark /ceug /ceugbarking /ciuppy -# /cf /cfat /cfat/ctree /cfat/ctree/cmulberry /cfats /cfot /cfot/ctree/cmulberry /cjitty /cjittyfat -# /cgag /cgig /cgigbark /cgog /cgogbark /cgog/cbark /cgug /cgugbarking /ckuppy -# /ch /chat /chat/ctree /chat/ctree/cmulberry /chats /chot /chot/ctree/cmulberry /citty /cittyhat - ) - - @requests = %w( - / - /dig - /digging - /dogging - /dogbarking/ - /puppy/barking - /c - /cat - /cat/shrub - /cat/tree - /cat/tree/maple - /cat/tree/mulberry/tree - /cat/tree/oak - /cats/ - /cats/tree - /cod - /zebra - ) - - @classifier = URIClassifier.new - @uris.each do |uri| - @classifier.register(uri, 1) - end - - puts "#{@uris.size} URIs / #{@requests.size * 10000} requests" - - Benchmark.bm do |x| - x.report do - # require 'ruby-prof' - # profile = RubyProf.profile do - 10000.times do - @requests.each do |request| - @classifier.resolve(request) - end - end - # end - # File.open("profile.html", 'w') { |file| RubyProf::GraphHtmlPrinter.new(profile).print(file, 0) } - end - end - end - end - -end - -- cgit v1.2.3-24-ge0c7