about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-28 02:17:25 +0000
committerEric Wong <normalperson@yhbt.net>2010-10-28 02:17:25 +0000
commitc4579db76b9ed5b0286fad852e798e8a890f093c (patch)
tree71ff2073fc59b20467bdcd0b7b37fe7841099c84
parent83644e02068311c7ff9cdbc63efd4764d1518138 (diff)
downloadrainbows-c4579db76b9ed5b0286fad852e798e8a890f093c.tar.gz
For consistency, changed settings are reset back to
their default values if they are removed or commented
out from the config file.
-rw-r--r--lib/rainbows/http_server.rb26
-rw-r--r--lib/rainbows/never_block.rb7
-rw-r--r--t/t0018-reload-restore-settings.sh60
3 files changed, 83 insertions, 10 deletions
diff --git a/lib/rainbows/http_server.rb b/lib/rainbows/http_server.rb
index 3826a23..33aa309 100644
--- a/lib/rainbows/http_server.rb
+++ b/lib/rainbows/http_server.rb
@@ -24,8 +24,6 @@ class Rainbows::HttpServer < Unicorn::HttpServer
       G.quit! # let the master reopen and refork us
   end
 
-  #:stopdoc:
-  #
   # Add one second to the timeout since our fchmod heartbeat is less
   # precise (and must be more conservative) than Unicorn does.  We
   # handle many clients per process and can't chmod on every
@@ -35,7 +33,23 @@ class Rainbows::HttpServer < Unicorn::HttpServer
   def timeout=(nr)
     @timeout = nr + 1
   end
-  #:startdoc:
+
+  def load_config!
+    use :Base
+    G.kato = 5
+    Rainbows.max_bytes = 1024 * 1024
+    @worker_connections = nil
+    super
+    @worker_connections ||= Rainbows::MODEL_WORKER_CONNECTIONS[@use]
+  end
+
+  def ready_pipe=(v)
+    # hacky hook got force Rainbows! to load modules only in workers
+    if @master_pid && @master_pid == Process.ppid
+      extend(Rainbows.const_get(@use))
+    end
+    super
+  end
 
   def use(*args)
     model = args.shift or return @use
@@ -49,7 +63,6 @@ class Rainbows::HttpServer < Unicorn::HttpServer
 
     Module === mod or
       raise ArgumentError, "concurrency model #{model.inspect} not supported"
-    extend(mod)
     args.each do |opt|
       case opt
       when Hash; O.update(opt)
@@ -61,11 +74,8 @@ class Rainbows::HttpServer < Unicorn::HttpServer
     new_defaults = {
       'rainbows.model' => (@use = model.to_sym),
       'rack.multithread' => !!(model.to_s =~ /Thread/),
+      'rainbows.autochunk' => [:Rev,:EventMachine,:NeverBlock].include?(@use),
     }
-    case @use
-    when :Rev, :EventMachine, :NeverBlock
-      new_defaults['rainbows.autochunk'] = true
-    end
     Rainbows::Const::RACK_DEFAULTS.update(new_defaults)
   end
 
diff --git a/lib/rainbows/never_block.rb b/lib/rainbows/never_block.rb
index 9f050a5..308398e 100644
--- a/lib/rainbows/never_block.rb
+++ b/lib/rainbows/never_block.rb
@@ -31,8 +31,11 @@ module Rainbows
         raise ArgumentError, "pool_size must a be an Integer > 0"
       mod = Rainbows.const_get(O[:backend])
       require "never_block" # require EM first since we need a higher version
-      G.server.extend(mod)
-      G.server.extend(Core)
+    end
+
+    def self.extended(klass)
+      klass.extend(Rainbows.const_get(O[:backend])) # EventMachine
+      klass.extend(Core)
     end
 
     module Core  # :nodoc: all
diff --git a/t/t0018-reload-restore-settings.sh b/t/t0018-reload-restore-settings.sh
new file mode 100644
index 0000000..fc61f0c
--- /dev/null
+++ b/t/t0018-reload-restore-settings.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+. ./test-lib.sh
+t_plan 8 "reload restore settings for $model"
+
+t_begin "setup and start" && {
+        rtmpfiles orig_config
+        rainbows_setup
+        cat $unicorn_config > $orig_config
+        rainbows -D -c $unicorn_config -l $listen env.ru
+        rainbows_wait_start
+}
+
+t_begin "HTTP request confirms we're running the correct model" && {
+        curl -sSfv http://$listen/ | grep "\"rainbows.model\"=>:$model"
+}
+
+t_begin "clobber config and reload" && {
+        cat > $unicorn_config <<EOF
+stderr_path "$r_err"
+EOF
+        kill -HUP $rainbows_pid
+        while ! egrep '(done|error) reloading' $r_err >/dev/null
+        do
+                sleep 1
+        done
+
+        grep 'done reloading' $r_err >/dev/null
+}
+
+t_begin "HTTP request confirms we're on the default model" && {
+        curl -sSfv http://$listen/ | \
+          grep "\"rainbows.model\"=>:Base" >/dev/null
+}
+
+t_begin "restore config and reload" && {
+        cat $orig_config > $unicorn_config
+        > $r_err
+        kill -HUP $rainbows_pid
+        rainbows_wait_start
+        while ! egrep '(done|error) reloading' $r_err >/dev/null
+        do
+                sleep 1
+        done
+        grep 'done reloading' $r_err >/dev/null
+}
+
+t_begin "HTTP request confirms we're back on the correct model" && {
+        curl -sSfv http://$listen/ | \
+          grep "\"rainbows.model\"=>:$model" >/dev/null
+}
+
+t_begin "killing succeeds" && {
+        kill $rainbows_pid
+}
+
+t_begin "check stderr" && {
+        check_stderr
+}
+
+t_done