Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix up failing tests broke by 2316e7d

  • Loading branch information...
commit f98d8ee72b2fd92bf0e09f3cade60add9efd3a15 1 parent 2316e7d
@josh josh authored
Showing with 37 additions and 36 deletions.
  1. +6 −6 railties/lib/fcgi_handler.rb
  2. +31 −30 railties/test/fcgi_dispatcher_test.rb
View
12 railties/lib/fcgi_handler.rb
@@ -71,7 +71,7 @@ def process!(provider = FCGI)
protected
def process_each_request(provider)
- cgi = nil
+ request = nil
catch :exit do
provider.each do |request|
@@ -81,17 +81,17 @@ def process_each_request(provider)
when :reload
reload!
when :restart
- close_connection(cgi)
+ close_connection(request)
restart!
when :exit
- close_connection(cgi)
+ close_connection(request)
throw :exit
end
end
end
rescue SignalException => signal
raise unless signal.message == 'SIGUSR1'
- close_connection(cgi)
+ close_connection(request)
end
def process_request(request)
@@ -233,7 +233,7 @@ def gc_countdown
end
end
- def close_connection(cgi)
- cgi.instance_variable_get("@request").finish if cgi
+ def close_connection(request)
+ request.finish if request
end
end
View
61 railties/test/fcgi_dispatcher_test.rb
@@ -4,6 +4,8 @@
require 'action_controller'
require 'fcgi_handler'
+Dispatcher.middleware.clear
+
class RailsFCGIHandlerTest < Test::Unit::TestCase
def setup
@log = StringIO.new
@@ -11,14 +13,14 @@ def setup
end
def test_process_restart
- cgi = mock
- FCGI.stubs(:each_cgi).yields(cgi)
+ request = mock
+ FCGI.stubs(:each).yields(request)
@handler.expects(:process_request).once
@handler.expects(:dispatcher_error).never
@handler.expects(:when_ready).returns(:restart)
- @handler.expects(:close_connection).with(cgi)
+ @handler.expects(:close_connection).with(request)
@handler.expects(:reload!).never
@handler.expects(:restart!)
@@ -26,14 +28,14 @@ def test_process_restart
end
def test_process_exit
- cgi = mock
- FCGI.stubs(:each_cgi).yields(cgi)
+ request = mock
+ FCGI.stubs(:each).yields(request)
@handler.expects(:process_request).once
@handler.expects(:dispatcher_error).never
@handler.expects(:when_ready).returns(:exit)
- @handler.expects(:close_connection).with(cgi)
+ @handler.expects(:close_connection).with(request)
@handler.expects(:reload!).never
@handler.expects(:restart!).never
@@ -41,8 +43,8 @@ def test_process_exit
end
def test_process_with_system_exit_exception
- cgi = mock
- FCGI.stubs(:each_cgi).yields(cgi)
+ request = mock
+ FCGI.stubs(:each).yields(request)
@handler.expects(:process_request).once.raises(SystemExit)
@handler.stubs(:dispatcher_log)
@@ -110,9 +112,9 @@ def test_restore!
end
def test_uninterrupted_processing
- cgi = mock
- FCGI.expects(:each_cgi).yields(cgi)
- @handler.expects(:process_request).with(cgi)
+ request = mock
+ FCGI.expects(:each).yields(request)
+ @handler.expects(:process_request).with(request)
@handler.process!
@@ -138,8 +140,8 @@ def setup
end
def test_interrupted_via_HUP_when_not_in_request
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
@handler.expects(:signal).times(2).returns('HUP')
@handler.expects(:reload!).once
@@ -151,13 +153,13 @@ def test_interrupted_via_HUP_when_not_in_request
end
def test_interrupted_via_USR1_when_not_in_request
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
@handler.expects(:signal).times(2).returns('USR1')
@handler.expects(:exit_handler).never
@handler.expects(:reload!).never
- @handler.expects(:close_connection).with(cgi).once
+ @handler.expects(:close_connection).with(request).once
@handler.expects(:exit).never
@handler.process!
@@ -165,13 +167,13 @@ def test_interrupted_via_USR1_when_not_in_request
end
def test_restart_via_USR2_when_in_request
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
@handler.expects(:signal).times(2).returns('USR2')
@handler.expects(:exit_handler).never
@handler.expects(:reload!).never
- @handler.expects(:close_connection).with(cgi).once
+ @handler.expects(:close_connection).with(request).once
@handler.expects(:exit).never
@handler.expects(:restart!).once
@@ -180,8 +182,8 @@ def test_restart_via_USR2_when_in_request
end
def test_interrupted_via_TERM
- cgi = mock
- FCGI.expects(:each_cgi).once.yields(cgi)
+ request = mock
+ FCGI.expects(:each).once.yields(request)
::Rack::Handler::FastCGI.expects(:serve).once.returns('TERM')
@handler.expects(:reload!).never
@@ -193,16 +195,16 @@ def test_interrupted_via_TERM
def test_runtime_exception_in_fcgi
error = RuntimeError.new('foo')
- FCGI.expects(:each_cgi).times(2).raises(error)
+ FCGI.expects(:each).times(2).raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^retrying/))
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
@handler.process!
end
def test_runtime_error_in_dispatcher
- cgi = mock
+ request = mock
error = RuntimeError.new('foo')
- FCGI.expects(:each_cgi).once.yields(cgi)
+ FCGI.expects(:each).once.yields(request)
::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^unhandled/))
@handler.process!
@@ -210,15 +212,15 @@ def test_runtime_error_in_dispatcher
def test_signal_exception_in_fcgi
error = SignalException.new('USR2')
- FCGI.expects(:each_cgi).once.raises(error)
+ FCGI.expects(:each).once.raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
@handler.process!
end
def test_signal_exception_in_dispatcher
- cgi = mock
+ request = mock
error = SignalException.new('USR2')
- FCGI.expects(:each_cgi).once.yields(cgi)
+ FCGI.expects(:each).once.yields(request)
::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
@handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
@handler.process!
@@ -247,9 +249,8 @@ def test_periodic_gc
@handler = RailsFCGIHandler.new(@log, 10)
assert_equal 10, @handler.gc_request_period
- cgi = mock
- FCGI.expects(:each_cgi).times(10).yields(cgi)
- Dispatcher.expects(:new).times(10)
+ request = mock
+ FCGI.expects(:each).times(10).yields(request)
@handler.expects(:run_gc!).never
9.times { @handler.process! }
Please sign in to comment.
Something went wrong with that request. Please try again.