Changeset 4913
- Timestamp:
- 09/03/06 00:18:31 (2 years ago)
- Files:
-
- trunk/railties/CHANGELOG (modified) (1 diff)
- trunk/railties/lib/fcgi_handler.rb (modified) (3 diffs)
- trunk/railties/test/abstract_unit.rb (added)
- trunk/railties/test/fcgi_dispatcher_test.rb (modified) (6 diffs)
- trunk/railties/test/mocks/routes.rb (added)
- trunk/railties/test/mocks/stubbed_breakpoint.rb (added)
- trunk/railties/test/mocks/stubbed_kernel.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/railties/CHANGELOG
r4899 r4913 1 1 *SVN* 2 3 * Thoroughly test the FCGI dispatcher. #5970 [Kevin Clark] 2 4 3 5 * Remove Dir.chdir in the Webrick DispatchServlet#initialize method. Fix bad path errors when trying to load config/routes.rb. [Rick Olson] trunk/railties/lib/fcgi_handler.rb
r4885 r4913 51 51 run_gc! if gc_request_period 52 52 53 provider.each_cgi do |cgi| 54 process_request(cgi) 55 56 case when_ready 57 when :reload 58 reload! 59 when :restart 60 close_connection(cgi) 61 restart! 62 when :exit 63 close_connection(cgi) 64 break 65 when :breakpoint 66 close_connection(cgi) 67 breakpoint! 68 end 69 70 gc_countdown 71 end 53 process_each_request!(provider) 72 54 73 55 GC.enable … … 88 70 end 89 71 end 90 91 92 pr ivate72 73 74 protected 93 75 def logger 94 76 @logger ||= Logger.new(@log_file_path) … … 145 127 dispatcher_log :info, "asked to breakpoint ASAP" 146 128 @when_ready = :breakpoint 129 end 130 131 def process_each_request!(provider) 132 provider.each_cgi do |cgi| 133 process_request(cgi) 134 135 case when_ready 136 when :reload 137 reload! 138 when :restart 139 close_connection(cgi) 140 restart! 141 when :exit 142 close_connection(cgi) 143 break 144 when :breakpoint 145 close_connection(cgi) 146 breakpoint! 147 end 148 149 gc_countdown 150 end 147 151 end 148 152 trunk/railties/test/fcgi_dispatcher_test.rb
r2847 r4913 1 $:.unshift File.dirname(__FILE__) + "/../lib" 1 require File.dirname(__FILE__) + "/abstract_unit" 2 2 3 $:.unshift File.dirname(__FILE__) + "/mocks" 3 4 4 require 'test/unit'5 5 require 'stringio' 6 7 # Stubs 6 8 require 'fcgi_handler' 7 8 RAILS_ROOT = File.dirname(__FILE__) if !defined?(RAILS_ROOT) 9 require 'routes' 10 require 'stubbed_breakpoint' 11 require 'stubbed_kernel' 9 12 10 13 class RailsFCGIHandler … … 27 30 @signal_handlers[which].call(which) 28 31 end 29 30 def restore! 31 @reloaded = true 32 end 33 34 def reload! 35 @reloaded = true 32 33 def breakpoint 36 34 end 37 35 … … 54 52 end 55 53 54 def test_process_restart 55 @handler.stubs(:when_ready).returns(:restart) 56 57 @handler.expects(:close_connection) 58 @handler.expects(:restart!) 59 @handler.process! 60 end 61 62 def test_process_exit 63 @handler.stubs(:when_ready).returns(:exit) 64 65 @handler.expects(:close_connection) 66 @handler.process! 67 end 68 69 def test_process_breakpoint 70 @handler.stubs(:when_ready).returns(:breakpoint) 71 72 @handler.expects(:close_connection) 73 @handler.expects(:breakpoint!) 74 @handler.process! 75 end 76 77 def test_process_with_system_exit_exception 78 @handler.stubs(:process_request).raises(SystemExit) 79 80 @handler.expects(:dispatcher_log).with(:info, "terminated by explicit exit") 81 @handler.process! 82 end 83 84 def test_restart_handler 85 @handler.expects(:dispatcher_log).with(:info, "asked to restart ASAP") 86 87 @handler.send(:restart_handler, nil) 88 assert_equal :restart, @handler.when_ready 89 end 90 91 def test_breakpoint_handler 92 @handler.expects(:dispatcher_log).with(:info, "asked to breakpoint ASAP") 93 94 @handler.send(:breakpoint_handler, nil) 95 assert_equal :breakpoint, @handler.when_ready 96 end 97 98 def test_install_signal_handler_should_log_on_bad_signal 99 @handler.stubs(:trap).raises(ArgumentError) 100 101 @handler.expects(:dispatcher_log).with(:warn, "Ignoring unsupported signal CHEESECAKE.") 102 @handler.send(:install_signal_handler, "CHEESECAKE", nil) 103 end 104 105 def test_reload 106 @handler.expects(:restore!) 107 @handler.expects(:dispatcher_log).with(:info, "reloaded") 108 109 @handler.send(:reload!) 110 assert_nil @handler.when_ready 111 end 112 113 114 def test_reload_runs_gc_when_gc_request_period_set 115 @handler.expects(:run_gc!) 116 @handler.expects(:restore!) 117 @handler.expects(:dispatcher_log).with(:info, "reloaded") 118 @handler.gc_request_period = 10 119 @handler.send(:reload!) 120 end 121 122 def test_reload_doesnt_run_gc_if_gc_request_period_isnt_set 123 @handler.expects(:run_gc!).never 124 @handler.expects(:restore!) 125 @handler.expects(:dispatcher_log).with(:info, "reloaded") 126 @handler.send(:reload!) 127 end 128 129 def test_restart! 130 @handler.expects(:dispatcher_log).with(:info, "restarted") 131 assert_equal true, @handler.send(:restart!), "Exec wasn't run" 132 end 133 134 def test_restore! 135 $".expects(:replace) 136 Dispatcher.expects(:reset_application!) 137 ActionController::Routing::Routes.expects(:reload) 138 @handler.send(:restore!) 139 end 140 141 def test_breakpoint! 142 @handler.expects(:require).with('breakpoint') 143 Breakpoint.expects(:activate_drb) 144 @handler.expects(:breakpoint) 145 @handler.expects(:dispatcher_log).with(:info, "breakpointing") 146 @handler.send(:breakpoint!) 147 assert_nil @handler.when_ready 148 end 149 56 150 def test_uninterrupted_processing 57 151 @handler.process! … … 61 155 62 156 def test_interrupted_via_HUP_when_not_in_request 157 @handler.expects(:reload!) 63 158 FCGI.time_to_sleep = 1 64 159 @handler.thread = Thread.new { @handler.process! } … … 68 163 assert_nil @handler.exit_code 69 164 assert_equal :reload, @handler.when_ready 70 assert @handler.reloaded71 165 end 72 166 73 167 def test_interrupted_via_HUP_when_in_request 168 @handler.expects(:reload!) 169 74 170 Dispatcher.time_to_sleep = 1 75 171 @handler.thread = Thread.new { @handler.process! } … … 79 175 assert_nil @handler.exit_code 80 176 assert_equal :reload, @handler.when_ready 81 assert @handler.reloaded82 177 end 83 178