From 24e821bbf3e581b410d82aeb2203bc6311d5995e Mon Sep 17 00:00:00 2001 From: Ian Ownbey Date: Sat, 31 Jan 2009 14:40:57 -0800 Subject: Fixed test threading? --- test/unit/test_threading.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/unit/test_threading.rb b/test/unit/test_threading.rb index e577bbb..cfd4745 100644 --- a/test/unit/test_threading.rb +++ b/test/unit/test_threading.rb @@ -3,7 +3,7 @@ require File.join(root_dir, "test/test_helper") include Mongrel -class FakeHandler < Mongrel::HttpHandler +class FakeHandler @@concurrent_threads = 0 @@max_concurrent_threads = 0 @@ -16,14 +16,14 @@ class FakeHandler < Mongrel::HttpHandler @@mutex = Mutex.new end - def process(request, response) + def call(env) @@mutex.synchronize do @@concurrent_threads += 1 # !!! same for += and -= @@max_concurrent_threads = [@@concurrent_threads, @@max_concurrent_threads].max end sleep(0.1) - response.socket.write("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nhello!\n") + [200, {'Content-Type' => 'text/plain'}, ['hello!']] ensure @@mutex.synchronize { @@concurrent_threads -= 1 } end @@ -33,15 +33,14 @@ class ThreadingTest < Test::Unit::TestCase def setup @valid_request = "GET / HTTP/1.1\r\nHost: www.google.com\r\nContent-Type: text/plain\r\n\r\n" @port = process_based_port - + @app = Rack::URLMap.new('/test' => FakeHandler.new) @max_concurrent_threads = 4 redirect_test_io do - @server = HttpServer.new("127.0.0.1", @port, :max_concurrent_threads => @max_concurrent_threads) + @server = HttpServer.new("127.0.0.1", @port, @app, :max_concurrent_threads => @max_concurrent_threads) end - @server.register("/test", FakeHandler.new) redirect_test_io do - @server.run + @server.start! end end @@ -79,4 +78,4 @@ class ThreadingTest < Test::Unit::TestCase socket.write(" ") # Some platforms only raise the exception on attempted write socket.flush end -end \ No newline at end of file +end -- cgit v1.2.3-24-ge0c7