Skip to content
This repository
Browse code

Rewrite FCGI handler test

  • Loading branch information...
commit 20d6938453f439531a13e2ef1fd0905edf56294c 1 parent 7de5f69
Joshua Peek josh authored
4 railties/lib/rails/fcgi_handler.rb
@@ -216,7 +216,9 @@ def mark_features!
216 216
217 217 def restore!
218 218 $".replace @features
219   - Dispatcher.reset_application!
  219 + # TODO: Reloading the application should be the "Application"s
  220 + # responsibility
  221 + ActionDispatch::Callbacks.new(lambda {}, true)
220 222 ActionController::Routing::Routes.reload
221 223 end
222 224
12 railties/test/abstract_unit.rb
@@ -25,15 +25,3 @@
25 25 else
26 26 RAILS_ROOT = File.dirname(__FILE__)
27 27 end
28   -
29   -def uses_gem(gem_name, test_name, version = '> 0')
30   - begin
31   - require gem_name.to_s
32   - rescue LoadError
33   - gem gem_name.to_s, version
34   - require gem_name.to_s
35   - end
36   - yield
37   -rescue LoadError
38   - $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
39   -end
64 railties/test/fcgi_dispatcher_test.rb → railties/test/application/fcgi_dispatcher_test.rb
... ... @@ -1,18 +1,25 @@
1   -require 'abstract_unit'
  1 +require 'isolation/abstract_unit'
  2 +require 'mocha'
2 3
3   -uses_gem "fcgi", "0.8.7" do
  4 +begin
4 5
5   -require 'action_controller'
6   -require 'rails/fcgi_handler'
7   -
8   -module Rails
9   - def self.application
10   - ActionController::Routing::Routes
11   - end
  6 +begin
  7 + require 'fcgi'
  8 +rescue LoadError
  9 + gem 'fcgi', '0.8.7'
  10 + require 'fcgi'
12 11 end
13 12
14 13 class RailsFCGIHandlerTest < Test::Unit::TestCase
  14 + include ActiveSupport::Testing::Isolation
  15 +
15 16 def setup
  17 + build_app
  18 + boot_rails
  19 +
  20 + require "#{rails_root}/config/environment"
  21 + require 'rails/fcgi_handler'
  22 +
16 23 @log = StringIO.new
17 24 @handler = RailsFCGIHandler.new(@log)
18 25 end
@@ -87,7 +94,6 @@ def test_reload
87 94 assert_nil @handler.when_ready
88 95 end
89 96
90   -
91 97 def test_reload_runs_gc_when_gc_request_period_set
92 98 @handler.expects(:run_gc!)
93 99 @handler.expects(:restore!)
@@ -111,7 +117,6 @@ def test_restart!
111 117
112 118 def test_restore!
113 119 $".expects(:replace)
114   - Dispatcher.expects(:reset_application!)
115 120 ActionController::Routing::Routes.expects(:reload)
116 121 @handler.send(:restore!)
117 122 end
@@ -127,17 +132,24 @@ def test_uninterrupted_processing
127 132 end
128 133 end
129 134
130   -
131 135 class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
132   - class ::RailsFCGIHandler
133   - attr_accessor :signal
134   - alias_method :old_gc_countdown, :gc_countdown
135   - def gc_countdown
136   - signal ? Process.kill(signal, $$) : old_gc_countdown
137   - end
138   - end
  136 + include ActiveSupport::Testing::Isolation
139 137
140 138 def setup
  139 + build_app
  140 + boot_rails
  141 +
  142 + require "#{rails_root}/config/environment"
  143 + require 'rails/fcgi_handler'
  144 +
  145 + ::RailsFCGIHandler.class_eval do
  146 + attr_accessor :signal
  147 + alias_method :old_gc_countdown, :gc_countdown
  148 + def gc_countdown
  149 + signal ? Process.kill(signal, $$) : old_gc_countdown
  150 + end
  151 + end
  152 +
141 153 @log = StringIO.new
142 154 @handler = RailsFCGIHandler.new(@log)
143 155 @dispatcher = mock
@@ -232,9 +244,16 @@ def test_signal_exception_in_dispatcher
232 244 end
233 245 end
234 246
235   -
236 247 class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase
  248 + include ActiveSupport::Testing::Isolation
  249 +
237 250 def setup
  251 + build_app
  252 + boot_rails
  253 +
  254 + require "#{rails_root}/config/environment"
  255 + require 'rails/fcgi_handler'
  256 +
238 257 @log = StringIO.new
239 258 end
240 259
@@ -265,4 +284,7 @@ def test_periodic_gc
265 284 assert_nil @handler.when_ready
266 285 end
267 286 end
268   -end # uses_gem "fcgi"
  287 +
  288 +rescue LoadError
  289 + $stderr.puts 'Skipping fcgi tests. `gem install fcgi` and try again.'
  290 +end

0 comments on commit 20d6938

Please sign in to comment.
Something went wrong with that request. Please try again.