rainbows 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. data/GIT-VERSION-GEN +1 -1
  2. data/GNUmakefile +12 -6
  3. data/README +3 -2
  4. data/Rakefile +3 -3
  5. data/TODO +2 -9
  6. data/lib/rainbows.rb +1 -0
  7. data/lib/rainbows/app_pool.rb +10 -6
  8. data/lib/rainbows/base.rb +1 -1
  9. data/lib/rainbows/const.rb +1 -1
  10. data/lib/rainbows/ev_core.rb +88 -0
  11. data/lib/rainbows/event_machine.rb +218 -0
  12. data/lib/rainbows/http_server.rb +4 -1
  13. data/lib/rainbows/rev.rb +21 -89
  14. data/lib/rainbows/revactor.rb +4 -10
  15. data/local.mk.sample +13 -7
  16. data/rainbows.gemspec +17 -2
  17. data/t/.gitignore +1 -0
  18. data/t/GNUmakefile +63 -40
  19. data/t/README +6 -2
  20. data/t/async_sinatra.ru +13 -0
  21. data/t/bin/unused_listen +1 -1
  22. data/t/large-file-response.ru +1 -0
  23. data/t/my-tap-lib.sh +200 -0
  24. data/t/simple-http_Base.ru +3 -0
  25. data/t/simple-http_EventMachine.ru +9 -0
  26. data/t/simple-http_Rev.ru +9 -0
  27. data/t/simple-http_Revactor.ru +10 -0
  28. data/t/simple-http_ThreadPool.ru +10 -0
  29. data/t/simple-http_ThreadSpawn.ru +10 -0
  30. data/t/t0000-simple-http.sh +142 -0
  31. data/t/t0001-unix-http.sh +103 -0
  32. data/t/t0002-graceful.sh +32 -0
  33. data/t/t0002-parser-error.sh +31 -0
  34. data/t/t0003-reopen-logs.sh +97 -0
  35. data/t/t0005-large-file-response.sh +83 -0
  36. data/t/t0100-rack-input-hammer.sh +45 -0
  37. data/t/t0101-rack-input-trailer.sh +68 -0
  38. data/t/t0200-async-response.sh +66 -0
  39. data/t/t0201-async-response-no-autochunk.sh +3 -0
  40. data/t/t0300-async_sinatra.sh +65 -0
  41. data/t/t9000-rack-app-pool.sh +45 -33
  42. data/t/test-lib.sh +67 -56
  43. metadata +26 -56
  44. data/t/lib-async-response-no-autochunk.sh +0 -6
  45. data/t/lib-async-response.sh +0 -45
  46. data/t/lib-graceful.sh +0 -40
  47. data/t/lib-input-trailer.sh +0 -63
  48. data/t/lib-large-file-response.sh +0 -45
  49. data/t/lib-parser-error.sh +0 -29
  50. data/t/lib-rack-input-hammer.sh +0 -38
  51. data/t/lib-reopen-logs.sh +0 -60
  52. data/t/lib-simple-http.sh +0 -92
  53. data/t/t0000-basic.sh +0 -2
  54. data/t/t1000-thread-pool-basic.sh +0 -2
  55. data/t/t1002-thread-pool-graceful.sh +0 -2
  56. data/t/t1003-thread-pool-reopen-logs.sh +0 -2
  57. data/t/t1004-thread-pool-async-response.sh +0 -45
  58. data/t/t1005-thread-pool-large-file-response.sh +0 -45
  59. data/t/t1006-thread-pool-async-response-no-autochunk.sh +0 -6
  60. data/t/t1100-thread-pool-rack-input.sh +0 -2
  61. data/t/t1101-thread-pool-input-trailer.sh +0 -2
  62. data/t/t2000-thread-spawn-basic.sh +0 -2
  63. data/t/t2002-thread-spawn-graceful.sh +0 -2
  64. data/t/t2003-thread-spawn-reopen-logs.sh +0 -2
  65. data/t/t2004-thread-spawn-async-response.sh +0 -45
  66. data/t/t2005-thread-spawn-large-file-response.sh +0 -45
  67. data/t/t2006-thread-spawn-async-response-no-autochunk.sh +0 -6
  68. data/t/t2100-thread-spawn-rack-input.sh +0 -2
  69. data/t/t2101-thread-spawn-input-trailer.sh +0 -2
  70. data/t/t3000-revactor-basic.sh +0 -2
  71. data/t/t3002-revactor-graceful.sh +0 -2
  72. data/t/t3003-revactor-reopen-logs.sh +0 -2
  73. data/t/t3004-revactor-async-response.sh +0 -45
  74. data/t/t3005-revactor-large-file-response.sh +0 -2
  75. data/t/t3006-revactor-async-response-no-autochunk.sh +0 -6
  76. data/t/t3100-revactor-rack-input.sh +0 -2
  77. data/t/t3101-revactor-rack-input-trailer.sh +0 -2
  78. data/t/t4000-rev-basic.sh +0 -2
  79. data/t/t4002-rev-graceful.sh +0 -2
  80. data/t/t4003-rev-parser-error.sh +0 -2
  81. data/t/t4003-rev-reopen-logs.sh +0 -2
  82. data/t/t4004-rev-async-response.sh +0 -45
  83. data/t/t4005-rev-large-file-response.sh +0 -2
  84. data/t/t4006-rev-async-response-no-autochunk.sh +0 -6
  85. data/t/t4100-rev-rack-input.sh +0 -2
  86. data/t/t4101-rev-rack-input-trailer.sh +0 -2
@@ -1,36 +1,48 @@
1
1
  #!/bin/sh
2
2
  . ./test-lib.sh
3
+ case $model in
4
+ Thread*) ;;
5
+ *)
6
+ t_info "skipping $T since it's not compatible with $model"
7
+ exit 0
8
+ ;;
9
+ esac
10
+ nr_client=30 APP_POOL_SIZE=4
3
11
 
4
- eval $(unused_listen)
5
- rtmpfiles unicorn_config pid r_err r_out curl_out curl_err
6
-
7
- nr_client=30
8
-
9
- cat > $unicorn_config <<EOF
10
- listen "$listen"
11
- pid "$pid"
12
- stderr_path "$r_err"
13
- stdout_path "$r_out"
14
- Rainbows! do
15
- use :ThreadSpawn
16
- worker_connections 50
17
- end
18
- EOF
19
-
20
- APP_POOL_SIZE=4
21
- APP_POOL_SIZE=$APP_POOL_SIZE rainbows -D t9000.ru -c $unicorn_config
22
- wait_for_pid $pid
23
-
24
- start=$(date +%s)
25
- for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
26
- do
27
- ( curl -sSf http://$listen/ >> $curl_out 2>> $curl_err ) &
28
- done
29
- wait
30
- echo elapsed=$(( $(date +%s) - $start ))
31
- kill $(cat $pid)
32
-
33
- test $APP_POOL_SIZE -eq $(sort < $curl_out | uniq | wc -l)
34
- test ! -s $curl_err
35
-
36
- check_stderr
12
+ t_plan 6 "AppPool Rack middleware test for $model"
13
+
14
+ t_begin "configure and start" && {
15
+ rtmpfiles curl_out curl_err
16
+ rainbows_setup $model 50
17
+ APP_POOL_SIZE=$APP_POOL_SIZE rainbows -D t9000.ru -c $unicorn_config
18
+ rainbows_wait_start
19
+ }
20
+
21
+ t_begin "launch $nr_client requests" && {
22
+ start=$(date +%s)
23
+ seq="$(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)"
24
+ for i in $seq
25
+ do
26
+ curl -sSf http://$listen/ >> $curl_out 2>> $curl_err &
27
+ done
28
+ wait
29
+ t_info elapsed=$(( $(date +%s) - $start ))
30
+ }
31
+
32
+ t_begin "kill server" && {
33
+ kill $rainbows_pid
34
+ }
35
+
36
+ t_begin "$APP_POOL_SIZE instances of app were used" && {
37
+ test $APP_POOL_SIZE -eq $(sort < $curl_out | uniq | wc -l)
38
+ }
39
+
40
+ t_begin "no errors in curl stderr" && {
41
+ test ! -s $curl_err
42
+ }
43
+
44
+ t_begin "no errors in Rainbows! stderr" && {
45
+ check_stderr
46
+ }
47
+
48
+ t_done
data/t/test-lib.sh CHANGED
@@ -1,63 +1,21 @@
1
1
  #!/bin/sh
2
2
  # Copyright (c) 2009 Rainbows! developers
3
+ . ./my-tap-lib.sh
3
4
 
4
- # pipefail is non-POSIX, but useful in ksh/bash
5
- (
6
- set +e
7
- set -o pipefail 2>/dev/null
8
- )
9
- if test $? -eq 0
10
- then
11
- set -o pipefail
12
- else
13
- echo >&2 "WARNING: your shell does not understand pipefail"
14
- fi
15
-
16
- set -e
17
-
18
- T=$(basename $0)
5
+ set +u
19
6
  if test -z "$model"
20
7
  then
21
- case $T in
22
- t1???-thread-pool-*.sh) model=ThreadPool ;;
23
- t2???-thread-spawn-*.sh) model=ThreadSpawn ;;
24
- t3???-revactor-*.sh) model=Revactor ;;
25
- t4???-rev-*.sh) model=Rev ;;
26
- *) model=any ;;
27
- esac
8
+ # defaulting to Base would unfortunately fail some concurrency tests
9
+ model=ThreadSpawn
10
+ t_info "model undefined, defaulting to $model"
28
11
  fi
29
12
 
30
- ruby="${ruby-'ruby'}"
31
- RUBY_VERSION=${RUBY_VERSION-$($ruby -e 'puts RUBY_VERSION')}
32
- t_pfx=$PWD/trash/$T-$RUBY_VERSION
13
+ set -e
14
+ RUBY="${RUBY-ruby}"
15
+ RUBY_VERSION=${RUBY_VERSION-$($RUBY -e 'puts RUBY_VERSION')}
16
+ t_pfx=$PWD/trash/$model.$T-$RUBY_VERSION
33
17
  set -u
34
18
 
35
- # ensure a sane environment
36
- TZ=UTC LC_ALL=C LANG=C
37
- export LANG LC_ALL TZ
38
- unset CDPATH
39
-
40
- die () {
41
- echo >&2 "$@"
42
- exit 1
43
- }
44
-
45
- _test_on_exit () {
46
- code=$?
47
- case $code in
48
- 0)
49
- echo "ok $T"
50
- rm -f $_TEST_OK_RM_LIST
51
- ;;
52
- *) echo "not ok $T" ;;
53
- esac
54
- rm -f $_TEST_RM_LIST
55
- exit $code
56
- }
57
-
58
- _TEST_RM_LIST=
59
- _TEST_OK_RM_LIST=
60
- trap _test_on_exit EXIT
61
19
  PATH=$PWD/bin:$PATH
62
20
  export PATH
63
21
 
@@ -73,12 +31,13 @@ wait_for_pid () {
73
31
  done
74
32
  }
75
33
 
34
+ # requires $1 and prints out the value of $2
76
35
  require_check () {
77
36
  lib=$1
78
37
  const=$2
79
- if ! $ruby -r$lib -e "puts $const" >/dev/null 2>&1
38
+ if ! $RUBY -r$lib -e "puts $const" >/dev/null 2>&1
80
39
  then
81
- echo >&2 "skipping $T since we don't have $lib"
40
+ t_info "skipping $T since we don't have $lib"
82
41
  exit 0
83
42
  fi
84
43
  }
@@ -90,15 +49,21 @@ rtmpfiles () {
90
49
  do
91
50
  name=$id
92
51
  _tmp=$t_pfx.$id
93
- > $_tmp
94
52
  eval "$id=$_tmp"
95
- _TEST_OK_RM_LIST="$_TEST_OK_RM_LIST $_tmp"
96
53
 
97
54
  case $name in
98
55
  *fifo)
99
56
  rm -f $_tmp
100
57
  mkfifo $_tmp
101
- _TEST_RM_LIST="$_TEST_RM_LIST $_tmp"
58
+ T_RM_LIST="$T_RM_LIST $_tmp"
59
+ ;;
60
+ *socket)
61
+ rm -f $_tmp
62
+ T_RM_LIST="$T_RM_LIST $_tmp"
63
+ ;;
64
+ *)
65
+ > $_tmp
66
+ T_OK_RM_LIST="$T_OK_RM_LIST $_tmp"
102
67
  ;;
103
68
  esac
104
69
  done
@@ -124,7 +89,53 @@ check_stderr () {
124
89
  fi
125
90
  }
126
91
 
92
+ # rainbows_setup [ MODEL [ WORKER_CONNECTIONS ] ]
93
+ rainbows_setup () {
94
+ eval $(unused_listen)
95
+ rtmpfiles unicorn_config pid r_err r_out fifo tmp ok
96
+ cat > $unicorn_config <<EOF
97
+ listen "$listen"
98
+ pid "$pid"
99
+ stderr_path "$r_err"
100
+ stdout_path "$r_out"
101
+
102
+ # close my-tap-lib.sh FDs
103
+ unless ENV['UNICORN_FD']
104
+ IO.for_fd(3).close rescue nil
105
+ IO.for_fd(4).close rescue nil
106
+ end
107
+
108
+ before_fork do |server, worker|
109
+ # test script will block while reading from $fifo,
110
+ # so notify the script on the first worker we spawn
111
+ # by opening the FIFO
112
+ if worker.nr == 0
113
+ File.open("$fifo", "wb").close
114
+ end
115
+ end
116
+ EOF
117
+ {
118
+ if test $# -ge 1
119
+ then
120
+ echo 'Rainbows! do'
121
+ echo " use :$1"
122
+ test $# -eq 2 && echo " worker_connections $2"
123
+ echo end
124
+ else
125
+ echo "Rainbows! { use :$model }"
126
+ fi
127
+ } >> $unicorn_config
128
+ }
129
+
130
+ rainbows_wait_start () {
131
+ # "cat $fifo" will block until the before_fork hook is called in
132
+ # the Unicorn config file
133
+ test x = x"$(cat $fifo)"
134
+ rainbows_pid=$(cat $pid)
135
+ }
136
+
127
137
  case $model in
128
138
  Rev) require_check rev Rev::VERSION ;;
129
139
  Revactor) require_check revactor Revactor::VERSION ;;
140
+ EventMachine) require_check eventmachine EventMachine::VERSION ;;
130
141
  esac
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rainbows
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rainbows! developers
@@ -9,19 +9,9 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-19 00:00:00 -07:00
12
+ date: 2009-10-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rack
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
15
  - !ruby/object:Gem::Dependency
26
16
  name: unicorn
27
17
  type: :runtime
@@ -30,7 +20,7 @@ dependencies:
30
20
  requirements:
31
21
  - - ~>
32
22
  - !ruby/object:Gem::Version
33
- version: 0.93.1
23
+ version: 0.93.4
34
24
  version:
35
25
  description: |-
36
26
  Rainbows! is a HTTP server for sleepy Rack applications. It is based on
@@ -52,6 +42,8 @@ extra_rdoc_files:
52
42
  - lib/rainbows/base.rb
53
43
  - lib/rainbows/const.rb
54
44
  - lib/rainbows/dev_fd_response.rb
45
+ - lib/rainbows/ev_core.rb
46
+ - lib/rainbows/event_machine.rb
55
47
  - lib/rainbows/http_response.rb
56
48
  - lib/rainbows/http_server.rb
57
49
  - lib/rainbows/rev.rb
@@ -93,6 +85,8 @@ files:
93
85
  - lib/rainbows/base.rb
94
86
  - lib/rainbows/const.rb
95
87
  - lib/rainbows/dev_fd_response.rb
88
+ - lib/rainbows/ev_core.rb
89
+ - lib/rainbows/event_machine.rb
96
90
  - lib/rainbows/http_response.rb
97
91
  - lib/rainbows/http_server.rb
98
92
  - lib/rainbows/rev.rb
@@ -109,62 +103,38 @@ files:
109
103
  - t/README
110
104
  - t/async-response-no-autochunk.ru
111
105
  - t/async-response.ru
106
+ - t/async_sinatra.ru
112
107
  - t/bin/content-md5-put
113
108
  - t/bin/unused_listen
114
109
  - t/bin/utee
115
110
  - t/content-md5.ru
116
111
  - t/env.ru
117
112
  - t/large-file-response.ru
118
- - t/lib-async-response-no-autochunk.sh
119
- - t/lib-async-response.sh
120
- - t/lib-graceful.sh
121
- - t/lib-input-trailer.sh
122
- - t/lib-large-file-response.sh
123
- - t/lib-parser-error.sh
124
- - t/lib-rack-input-hammer.sh
125
- - t/lib-reopen-logs.sh
126
- - t/lib-simple-http.sh
113
+ - t/my-tap-lib.sh
127
114
  - t/sha1.ru
115
+ - t/simple-http_Base.ru
116
+ - t/simple-http_EventMachine.ru
117
+ - t/simple-http_Rev.ru
118
+ - t/simple-http_Revactor.ru
119
+ - t/simple-http_ThreadPool.ru
120
+ - t/simple-http_ThreadSpawn.ru
128
121
  - t/sleep.ru
129
- - t/t0000-basic.sh
122
+ - t/t0000-simple-http.sh
130
123
  - t/t0000.ru
131
- - t/t1000-thread-pool-basic.sh
124
+ - t/t0001-unix-http.sh
125
+ - t/t0002-graceful.sh
126
+ - t/t0002-parser-error.sh
127
+ - t/t0003-reopen-logs.sh
128
+ - t/t0005-large-file-response.sh
129
+ - t/t0100-rack-input-hammer.sh
130
+ - t/t0101-rack-input-trailer.sh
131
+ - t/t0200-async-response.sh
132
+ - t/t0201-async-response-no-autochunk.sh
133
+ - t/t0300-async_sinatra.sh
132
134
  - t/t1000.ru
133
- - t/t1002-thread-pool-graceful.sh
134
- - t/t1003-thread-pool-reopen-logs.sh
135
- - t/t1004-thread-pool-async-response.sh
136
- - t/t1005-thread-pool-large-file-response.sh
137
- - t/t1006-thread-pool-async-response-no-autochunk.sh
138
- - t/t1100-thread-pool-rack-input.sh
139
- - t/t1101-thread-pool-input-trailer.sh
140
- - t/t2000-thread-spawn-basic.sh
141
135
  - t/t2000.ru
142
- - t/t2002-thread-spawn-graceful.sh
143
- - t/t2003-thread-spawn-reopen-logs.sh
144
- - t/t2004-thread-spawn-async-response.sh
145
- - t/t2005-thread-spawn-large-file-response.sh
146
- - t/t2006-thread-spawn-async-response-no-autochunk.sh
147
- - t/t2100-thread-spawn-rack-input.sh
148
- - t/t2101-thread-spawn-input-trailer.sh
149
- - t/t3000-revactor-basic.sh
150
136
  - t/t3000.ru
151
- - t/t3002-revactor-graceful.sh
152
- - t/t3003-revactor-reopen-logs.sh
153
- - t/t3004-revactor-async-response.sh
154
- - t/t3005-revactor-large-file-response.sh
155
- - t/t3006-revactor-async-response-no-autochunk.sh
156
- - t/t3100-revactor-rack-input.sh
157
- - t/t3101-revactor-rack-input-trailer.sh
158
- - t/t4000-rev-basic.sh
159
137
  - t/t4000.ru
160
- - t/t4002-rev-graceful.sh
161
- - t/t4003-rev-parser-error.sh
162
- - t/t4003-rev-reopen-logs.sh
163
- - t/t4004-rev-async-response.sh
164
- - t/t4005-rev-large-file-response.sh
165
- - t/t4006-rev-async-response-no-autochunk.sh
166
- - t/t4100-rev-rack-input.sh
167
- - t/t4101-rev-rack-input-trailer.sh
168
138
  - t/t9000-rack-app-pool.sh
169
139
  - t/t9000.ru
170
140
  - t/test-lib.sh
@@ -1,6 +0,0 @@
1
- #!/bin/sh
2
- CONFIG_RU=async-response-no-autochunk.ru
3
- . ./lib-async-response.sh
4
- test x"$(cat $a)" = x0123456789
5
- test x"$(cat $b)" = x0123456789
6
- test x"$(cat $c)" = x0123456789
@@ -1,45 +0,0 @@
1
- CONFIG_RU=${CONFIG_RU-'async-response.ru'}
2
- . ./test-lib.sh
3
- echo "async response for model=$model"
4
- eval $(unused_listen)
5
- rtmpfiles unicorn_config a b c r_err r_out pid curl_err
6
-
7
- cat > $unicorn_config <<EOF
8
- listen "$listen"
9
- stderr_path "$r_err"
10
- stdout_path "$r_out"
11
- pid "$pid"
12
- Rainbows! { use :$model }
13
- EOF
14
-
15
- # can't load Rack::Lint here since it'll cause Rev to slurp
16
- rainbows -E none -D $CONFIG_RU -c $unicorn_config
17
- wait_for_pid $pid
18
-
19
- t0=$(date +%s)
20
- ( curl --no-buffer -sSf http://$listen/ 2>> $curl_err | utee $a) &
21
- ( curl --no-buffer -sSf http://$listen/ 2>> $curl_err | utee $b) &
22
- ( curl --no-buffer -sSf http://$listen/ 2>> $curl_err | utee $c) &
23
- wait
24
- t1=$(date +%s)
25
-
26
- rainbows_pid=$(cat $pid)
27
- kill -QUIT $rainbows_pid
28
- elapsed=$(( $t1 - $t0 ))
29
- echo "elapsed=$elapsed < 30"
30
- test $elapsed -lt 30
31
-
32
- dbgcat a
33
- dbgcat b
34
- dbgcat c
35
- dbgcat r_err
36
- dbgcat curl_err
37
- test ! -s $curl_err
38
- check_stderr
39
-
40
- while kill -0 $rainbows_pid >/dev/null 2>&1
41
- do
42
- sleep 1
43
- done
44
-
45
- dbgcat r_err
data/t/lib-graceful.sh DELETED
@@ -1,40 +0,0 @@
1
- . ./test-lib.sh
2
- echo "graceful test for model=$model"
3
-
4
- eval $(unused_listen)
5
- rtmpfiles unicorn_config curl_out pid r_err r_out fifo
6
-
7
- cat > $unicorn_config <<EOF
8
- listen "$listen"
9
- stderr_path "$r_err"
10
- stdout_path "$r_out"
11
- pid "$pid"
12
- Rainbows! { use :$model }
13
- EOF
14
-
15
- rainbows -D sleep.ru -c $unicorn_config
16
- wait_for_pid $pid
17
- rainbows_pid=$(cat $pid)
18
-
19
- curl -sSfv -T- </dev/null http://$listen/5 > $curl_out 2> $fifo &
20
-
21
- awk -v rainbows_pid=$rainbows_pid '
22
- { print $0 }
23
- /100 Continue/ {
24
- print "awk: sending SIGQUIT to", rainbows_pid
25
- system("kill -QUIT "rainbows_pid)
26
- }' $fifo
27
- wait
28
-
29
- dbgcat r_err
30
-
31
- test x"$(wc -l < $curl_out)" = x1
32
- nr=$(sort < $curl_out | uniq | wc -l)
33
-
34
- test "$nr" -eq 1
35
- test x$(sort < $curl_out | uniq) = xHello
36
- check_stderr
37
- while kill -0 $rainbows_pid >/dev/null 2>&1
38
- do
39
- sleep 1
40
- done