Skip to content
This repository
Browse code

Fix FCGI dispatching tests

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit 36af857c435cbbdb43f5a7bed200ddaa5e10ef80 1 parent c20c72e
Mike Gunderloy authored December 28, 2008 lifo committed December 29, 2008

Showing 1 changed file with 7 additions and 42 deletions. Show diff stats Hide diff stats

  1. 49  railties/test/fcgi_dispatcher_test.rb
49  railties/test/fcgi_dispatcher_test.rb
... ...
@@ -1,10 +1,9 @@
1 1
 require 'abstract_unit'
2 2
 
3 3
 begin
  4
+require 'action_controller'
4 5
 require 'fcgi_handler'
5 6
 
6  
-module ActionController; module Routing; module Routes; end end end
7  
-
8 7
 class RailsFCGIHandlerTest < Test::Unit::TestCase
9 8
   def setup
10 9
     @log = StringIO.new
@@ -131,19 +130,11 @@ def gc_countdown
131 130
     end
132 131
   end
133 132
 
134  
-  class ::Dispatcher
135  
-    class << self
136  
-      attr_accessor :signal
137  
-      alias_method :old_dispatch, :dispatch
138  
-      def dispatch(cgi)
139  
-        signal ? Process.kill(signal, $$) : old_dispatch
140  
-      end
141  
-    end
142  
-  end
143  
-
144 133
   def setup
145 134
     @log = StringIO.new
146 135
     @handler = RailsFCGIHandler.new(@log)
  136
+    @dispatcher = mock
  137
+    Dispatcher.stubs(:new).returns(@dispatcher)
147 138
   end
148 139
 
149 140
   def test_interrupted_via_HUP_when_not_in_request
@@ -159,19 +150,6 @@ def test_interrupted_via_HUP_when_not_in_request
159 150
     assert_equal :reload, @handler.when_ready
160 151
   end
161 152
 
162  
-  def test_interrupted_via_HUP_when_in_request
163  
-    cgi = mock
164  
-    FCGI.expects(:each_cgi).once.yields(cgi)
165  
-    Dispatcher.expects(:signal).times(2).returns('HUP')
166  
-
167  
-    @handler.expects(:reload!).once
168  
-    @handler.expects(:close_connection).never
169  
-    @handler.expects(:exit).never
170  
-
171  
-    @handler.process!
172  
-    assert_equal :reload, @handler.when_ready
173  
-  end
174  
-
175 153
   def test_interrupted_via_USR1_when_not_in_request
176 154
     cgi = mock
177 155
     FCGI.expects(:each_cgi).once.yields(cgi)
@@ -186,19 +164,6 @@ def test_interrupted_via_USR1_when_not_in_request
186 164
     assert_nil @handler.when_ready
187 165
   end
188 166
 
189  
-  def test_interrupted_via_USR1_when_in_request
190  
-    cgi = mock
191  
-    FCGI.expects(:each_cgi).once.yields(cgi)
192  
-    Dispatcher.expects(:signal).times(2).returns('USR1')
193  
-
194  
-    @handler.expects(:reload!).never
195  
-    @handler.expects(:close_connection).with(cgi).once
196  
-    @handler.expects(:exit).never
197  
-
198  
-    @handler.process!
199  
-    assert_equal :exit, @handler.when_ready
200  
-  end
201  
-
202 167
   def test_restart_via_USR2_when_in_request
203 168
     cgi = mock
204 169
     FCGI.expects(:each_cgi).once.yields(cgi)
@@ -217,7 +182,7 @@ def test_restart_via_USR2_when_in_request
217 182
   def test_interrupted_via_TERM
218 183
     cgi = mock
219 184
     FCGI.expects(:each_cgi).once.yields(cgi)
220  
-    Dispatcher.expects(:signal).times(2).returns('TERM')
  185
+    ::Rack::Handler::FastCGI.expects(:serve).once.returns('TERM')
221 186
 
222 187
     @handler.expects(:reload!).never
223 188
     @handler.expects(:close_connection).never
@@ -238,7 +203,7 @@ def test_runtime_error_in_dispatcher
238 203
     cgi = mock
239 204
     error = RuntimeError.new('foo')
240 205
     FCGI.expects(:each_cgi).once.yields(cgi)
241  
-    Dispatcher.expects(:dispatch).once.with(cgi).raises(error)
  206
+    ::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
242 207
     @handler.expects(:dispatcher_error).with(error, regexp_matches(/^unhandled/))
243 208
     @handler.process!
244 209
   end
@@ -254,7 +219,7 @@ def test_signal_exception_in_dispatcher
254 219
     cgi = mock
255 220
     error = SignalException.new('USR2')
256 221
     FCGI.expects(:each_cgi).once.yields(cgi)
257  
-    Dispatcher.expects(:dispatch).once.with(cgi).raises(error)
  222
+    ::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
258 223
     @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
259 224
     @handler.process!
260 225
   end
@@ -284,7 +249,7 @@ def test_periodic_gc
284 249
 
285 250
     cgi = mock
286 251
     FCGI.expects(:each_cgi).times(10).yields(cgi)
287  
-    Dispatcher.expects(:dispatch).times(10).with(cgi)
  252
+    Dispatcher.expects(:new).times(10)
288 253
 
289 254
     @handler.expects(:run_gc!).never
290 255
     9.times { @handler.process! }

0 notes on commit 36af857

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