about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-27 01:20:47 -0700
committerEric Wong <normalperson@yhbt.net>2009-10-27 01:23:46 -0700
commite9152a8463d62e46a772843f66ddedef52cd0b2c (patch)
treeb786a54b439fea80f65f5ea3efe51c6c70e3c9b2
parent940501b7dade7a8ba3d1406ec62c28a682919fe0 (diff)
Also new are added basic HTTP tests for UNIX domain socket
handling (for all models, now, of course).
-rw-r--r--lib/rainbows/revactor.rb14
-rw-r--r--local.mk.sample2
-rw-r--r--rainbows.gemspec4
-rw-r--r--t/GNUmakefile1
-rwxr-xr-xt/t0001-unix-http.sh103
5 files changed, 111 insertions, 13 deletions
diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb
index d9f246b..ddcbc04 100644
--- a/lib/rainbows/revactor.rb
+++ b/lib/rainbows/revactor.rb
@@ -1,9 +1,6 @@
 # -*- encoding: binary -*-
 require 'revactor'
-
-# workaround revactor 0.1.4 still using the old Rev::Buffer
-# ref: http://rubyforge.org/pipermail/revactor-talk/2009-October/000034.html
-defined?(Rev::Buffer) or Rev::Buffer = IO::Buffer
+Revactor::VERSION >= '0.1.5' or abort 'revactor 0.1.5 is required'
 
 module Rainbows
 
@@ -137,16 +134,13 @@ module Rainbows
 
     def revactorize_listeners!
       LISTENERS.map! do |s|
-        if TCPServer === s
+        case s
+        when TCPServer
           ::Revactor::TCP.listen(s, nil)
-        elsif defined?(::Revactor::UNIX) && UNIXServer === s
+        when UNIXServer
           ::Revactor::UNIX.listen(s)
-        else
-          logger.error "your version of Revactor can't handle #{s.inspect}"
-          nil
         end
       end
-      LISTENERS.compact!
     end
 
   end
diff --git a/local.mk.sample b/local.mk.sample
index 1edf055..29a5f63 100644
--- a/local.mk.sample
+++ b/local.mk.sample
@@ -21,7 +21,7 @@ else
   prefix := $(prefix)/ruby-1.9
   export PATH := $(prefix)/bin:$(PATH)
   RUBY := $(prefix)/bin/ruby --disable-gems
-  gems += case-0.5 revactor-0.1.4
+  gems += case-0.5 revactor-0.1.5
   gem_paths := $(addprefix $(prefix)/lib/ruby/gems/1.9.1/gems/,$(gems))
 endif
 
diff --git a/rainbows.gemspec b/rainbows.gemspec
index fc70a48..26fae26 100644
--- a/rainbows.gemspec
+++ b/rainbows.gemspec
@@ -49,8 +49,8 @@ Gem::Specification.new do |s|
   # optional runtime dependencies depending on configuration
   # see local.mk.sample for the exact versions we've tested with
   #
-  # the next version of Revactor will include UNIX domain socket support
-  # s.add_dependency(%q<revactor>, [">= 0.1.4"])
+  # Revactor >= 0.1.5 includes UNIX domain socket support
+  # s.add_dependency(%q<revactor>, [">= 0.1.5"])
   #
   # Revactor depends on Rev, too, 0.3.0 got the ability to attach IOs
   # s.add_dependency(%q<rev>, [">= 0.3.0"])
diff --git a/t/GNUmakefile b/t/GNUmakefile
index 5129944..97f1f82 100644
--- a/t/GNUmakefile
+++ b/t/GNUmakefile
@@ -31,6 +31,7 @@ $(T): MODELS = $(models)
 
 # some tests can be run with all models
 t0000-simple-http.sh: MODELS = $(all_models)
+t0001-unix-http.sh: MODELS = $(all_models)
 t0002-graceful.sh: MODELS = $(all_models)
 t0002-parser-error.sh: MODELS = $(all_models)
 t0003-reopen-logs.sh: MODELS = $(all_models)
diff --git a/t/t0001-unix-http.sh b/t/t0001-unix-http.sh
new file mode 100755
index 0000000..59f996a
--- /dev/null
+++ b/t/t0001-unix-http.sh
@@ -0,0 +1,103 @@
+#!/bin/sh
+. ./test-lib.sh
+t_plan 18 "simple HTTP connection keepalive/pipelining tests for $model"
+
+t_begin "checking for config.ru for $model" && {
+        tbase=simple-http_$model.ru
+        test -f "$tbase"
+}
+
+t_begin "setup and start" && {
+        rtmpfiles unix_socket
+        rainbows_setup
+        echo "listen '$unix_socket'" >> $unicorn_config
+        rainbows -D $tbase -c $unicorn_config
+        rainbows_wait_start
+}
+
+t_begin "pid file exists" && {
+        test -f $pid
+}
+
+t_begin "single TCP request" && {
+        curl -sSfv http://$listen/
+}
+
+dbgcat r_err
+
+t_begin "pipelining partial requests" && {
+        req='GET / HTTP/1.1\r\nHost: example.com\r\n'
+        (
+                cat $fifo > $tmp &
+                printf "$req"'\r\n'"$req"
+                sleep 1
+                printf 'Connection: close\r\n\r\n'
+                wait
+                echo ok > $ok
+        ) | socat - UNIX:$unix_socket > $fifo
+}
+dbgcat tmp
+
+t_begin "two HTTP/1.1 responses" && {
+        test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
+}
+
+t_begin "two HTTP/1.1 200 OK responses" && {
+        test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
+}
+
+t_begin 'one "Connection: keep-alive" response' && {
+        test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
+}
+
+t_begin 'one "Connection: close" response' && {
+        test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
+}
+
+t_begin 'check subshell success' && {
+        test x"$(cat $ok)" = xok
+}
+
+
+t_begin "check stderr" && {
+        check_stderr
+}
+
+t_begin "burst pipelining requests" && {
+        req='GET / HTTP/1.1\r\nHost: example.com\r\n'
+        (
+                cat $fifo > $tmp &
+                printf "$req"'\r\n'"$req"'Connection: close\r\n\r\n'
+                wait
+                echo ok > $ok
+        ) | socat - UNIX:$unix_socket > $fifo
+}
+
+dbgcat tmp
+dbgcat r_err
+
+t_begin "two HTTP/1.1 responses" && {
+        test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
+}
+
+t_begin "two HTTP/1.1 200 OK responses" && {
+        test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
+}
+
+t_begin 'one "Connection: keep-alive" response' && {
+        test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
+}
+
+t_begin 'one "Connection: close" response' && {
+        test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
+}
+
+t_begin 'check subshell success' && {
+        test x"$(cat $ok)" = xok
+}
+
+t_begin "killing succeeds" && {
+        kill $rainbows_pid
+}
+
+t_done