unicorn-heroku 4.3.1.1.gc608.dirty

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/.CHANGELOG.old +25 -0
  2. data/.document +29 -0
  3. data/.gitignore +24 -0
  4. data/.mailmap +26 -0
  5. data/.wrongdoc.yml +10 -0
  6. data/Application_Timeouts +77 -0
  7. data/CONTRIBUTORS +35 -0
  8. data/COPYING +674 -0
  9. data/DESIGN +97 -0
  10. data/Documentation/.gitignore +5 -0
  11. data/Documentation/GNUmakefile +30 -0
  12. data/Documentation/unicorn.1.txt +174 -0
  13. data/Documentation/unicorn_rails.1.txt +175 -0
  14. data/FAQ +53 -0
  15. data/GIT-VERSION-GEN +40 -0
  16. data/GNUmakefile +294 -0
  17. data/HACKING +134 -0
  18. data/ISSUES +36 -0
  19. data/KNOWN_ISSUES +79 -0
  20. data/LICENSE +64 -0
  21. data/Links +56 -0
  22. data/PHILOSOPHY +145 -0
  23. data/README +154 -0
  24. data/Rakefile +97 -0
  25. data/SIGNALS +114 -0
  26. data/Sandbox +96 -0
  27. data/TODO +5 -0
  28. data/TUNING +98 -0
  29. data/bin/unicorn +121 -0
  30. data/bin/unicorn_rails +209 -0
  31. data/examples/big_app_gc.rb +2 -0
  32. data/examples/echo.ru +27 -0
  33. data/examples/git.ru +13 -0
  34. data/examples/init.sh +74 -0
  35. data/examples/logger_mp_safe.rb +25 -0
  36. data/examples/logrotate.conf +29 -0
  37. data/examples/nginx.conf +156 -0
  38. data/examples/unicorn.conf.minimal.rb +13 -0
  39. data/examples/unicorn.conf.rb +94 -0
  40. data/ext/unicorn_http/CFLAGS +13 -0
  41. data/ext/unicorn_http/c_util.h +124 -0
  42. data/ext/unicorn_http/common_field_optimization.h +111 -0
  43. data/ext/unicorn_http/ext_help.h +86 -0
  44. data/ext/unicorn_http/extconf.rb +10 -0
  45. data/ext/unicorn_http/global_variables.h +97 -0
  46. data/ext/unicorn_http/httpdate.c +82 -0
  47. data/ext/unicorn_http/unicorn_http.rl +1036 -0
  48. data/ext/unicorn_http/unicorn_http_common.rl +76 -0
  49. data/lib/unicorn.rb +107 -0
  50. data/lib/unicorn/app/exec_cgi.rb +154 -0
  51. data/lib/unicorn/app/inetd.rb +109 -0
  52. data/lib/unicorn/app/old_rails.rb +35 -0
  53. data/lib/unicorn/app/old_rails/static.rb +59 -0
  54. data/lib/unicorn/cgi_wrapper.rb +147 -0
  55. data/lib/unicorn/configurator.rb +630 -0
  56. data/lib/unicorn/const.rb +40 -0
  57. data/lib/unicorn/http_request.rb +77 -0
  58. data/lib/unicorn/http_response.rb +45 -0
  59. data/lib/unicorn/http_server.rb +744 -0
  60. data/lib/unicorn/launcher.rb +62 -0
  61. data/lib/unicorn/oob_gc.rb +71 -0
  62. data/lib/unicorn/preread_input.rb +33 -0
  63. data/lib/unicorn/socket_helper.rb +208 -0
  64. data/lib/unicorn/ssl_client.rb +11 -0
  65. data/lib/unicorn/ssl_configurator.rb +104 -0
  66. data/lib/unicorn/ssl_server.rb +42 -0
  67. data/lib/unicorn/stream_input.rb +149 -0
  68. data/lib/unicorn/tee_input.rb +126 -0
  69. data/lib/unicorn/tmpio.rb +29 -0
  70. data/lib/unicorn/util.rb +68 -0
  71. data/lib/unicorn/worker.rb +88 -0
  72. data/local.mk.sample +59 -0
  73. data/script/isolate_for_tests +50 -0
  74. data/setup.rb +1586 -0
  75. data/t/.gitignore +5 -0
  76. data/t/GNUmakefile +82 -0
  77. data/t/README +42 -0
  78. data/t/bin/content-md5-put +36 -0
  79. data/t/bin/sha1sum.rb +17 -0
  80. data/t/bin/unused_listen +40 -0
  81. data/t/bin/utee +12 -0
  82. data/t/broken-app.ru +12 -0
  83. data/t/detach.ru +11 -0
  84. data/t/env.ru +3 -0
  85. data/t/heartbeat-timeout.ru +12 -0
  86. data/t/my-tap-lib.sh +201 -0
  87. data/t/oob_gc.ru +21 -0
  88. data/t/oob_gc_path.ru +21 -0
  89. data/t/pid.ru +3 -0
  90. data/t/preread_input.ru +17 -0
  91. data/t/rack-input-tests.ru +21 -0
  92. data/t/rails3-app/.gitignore +4 -0
  93. data/t/rails3-app/Gemfile +26 -0
  94. data/t/rails3-app/Rakefile +10 -0
  95. data/t/rails3-app/app/controllers/application_controller.rb +4 -0
  96. data/t/rails3-app/app/helpers/application_helper.rb +2 -0
  97. data/t/rails3-app/app/views/layouts/application.html.erb +14 -0
  98. data/t/rails3-app/config.ru +4 -0
  99. data/t/rails3-app/config/application.rb +46 -0
  100. data/t/rails3-app/config/boot.rb +6 -0
  101. data/t/rails3-app/config/database.yml +22 -0
  102. data/t/rails3-app/config/environment.rb +5 -0
  103. data/t/rails3-app/config/environments/development.rb +19 -0
  104. data/t/rails3-app/config/environments/production.rb +42 -0
  105. data/t/rails3-app/config/environments/test.rb +32 -0
  106. data/t/rails3-app/config/initializers/backtrace_silencers.rb +7 -0
  107. data/t/rails3-app/config/initializers/inflections.rb +10 -0
  108. data/t/rails3-app/config/initializers/mime_types.rb +5 -0
  109. data/t/rails3-app/config/initializers/secret_token.rb +7 -0
  110. data/t/rails3-app/config/initializers/session_store.rb +8 -0
  111. data/t/rails3-app/config/locales/en.yml +5 -0
  112. data/t/rails3-app/config/routes.rb +58 -0
  113. data/t/rails3-app/db/seeds.rb +7 -0
  114. data/t/rails3-app/doc/README_FOR_APP +2 -0
  115. data/t/rails3-app/lib/tasks/.gitkeep +0 -0
  116. data/t/rails3-app/public/404.html +1 -0
  117. data/t/rails3-app/public/500.html +1 -0
  118. data/t/rails3-app/public/x.txt +1 -0
  119. data/t/rails3-app/script/rails +9 -0
  120. data/t/rails3-app/test/performance/browsing_test.rb +9 -0
  121. data/t/rails3-app/test/test_helper.rb +13 -0
  122. data/t/rails3-app/vendor/plugins/.gitkeep +0 -0
  123. data/t/sslgen.sh +71 -0
  124. data/t/t0000-http-basic.sh +50 -0
  125. data/t/t0001-reload-bad-config.sh +53 -0
  126. data/t/t0002-config-conflict.sh +49 -0
  127. data/t/t0002-parser-error.sh +94 -0
  128. data/t/t0003-working_directory.sh +51 -0
  129. data/t/t0004-heartbeat-timeout.sh +69 -0
  130. data/t/t0004-working_directory_broken.sh +24 -0
  131. data/t/t0005-working_directory_app.rb.sh +37 -0
  132. data/t/t0006-reopen-logs.sh +83 -0
  133. data/t/t0006.ru +13 -0
  134. data/t/t0007-working_directory_no_embed_cli.sh +44 -0
  135. data/t/t0008-back_out_of_upgrade.sh +110 -0
  136. data/t/t0009-broken-app.sh +56 -0
  137. data/t/t0009-winch_ttin.sh +59 -0
  138. data/t/t0010-reap-logging.sh +55 -0
  139. data/t/t0011-active-unix-socket.sh +79 -0
  140. data/t/t0012-reload-empty-config.sh +85 -0
  141. data/t/t0013-rewindable-input-false.sh +24 -0
  142. data/t/t0013.ru +12 -0
  143. data/t/t0014-rewindable-input-true.sh +24 -0
  144. data/t/t0014.ru +12 -0
  145. data/t/t0015-configurator-internals.sh +25 -0
  146. data/t/t0016-trust-x-forwarded-false.sh +30 -0
  147. data/t/t0017-trust-x-forwarded-true.sh +30 -0
  148. data/t/t0018-write-on-close.sh +23 -0
  149. data/t/t0019-max_header_len.sh +49 -0
  150. data/t/t0020-at_exit-handler.sh +49 -0
  151. data/t/t0021-process_detach.sh +29 -0
  152. data/t/t0100-rack-input-tests.sh +124 -0
  153. data/t/t0116-client_body_buffer_size.sh +80 -0
  154. data/t/t0116.ru +16 -0
  155. data/t/t0300-rails3-basic.sh +28 -0
  156. data/t/t0301-rails3-missing-config-ru.sh +33 -0
  157. data/t/t0302-rails3-alt-working_directory.sh +32 -0
  158. data/t/t0303-rails3-alt-working_directory_config.ru.sh +56 -0
  159. data/t/t0304-rails3-alt-working_directory_no_embed_cli.sh +52 -0
  160. data/t/t0600-https-server-basic.sh +48 -0
  161. data/t/t9000-preread-input.sh +48 -0
  162. data/t/t9001-oob_gc.sh +47 -0
  163. data/t/t9002-oob_gc-path.sh +75 -0
  164. data/t/test-lib.sh +113 -0
  165. data/t/test-rails3.sh +27 -0
  166. data/t/write-on-close.ru +11 -0
  167. data/test/aggregate.rb +15 -0
  168. data/test/benchmark/README +50 -0
  169. data/test/benchmark/dd.ru +18 -0
  170. data/test/benchmark/stack.ru +8 -0
  171. data/test/exec/README +5 -0
  172. data/test/exec/test_exec.rb +1055 -0
  173. data/test/rails/app-1.2.3/.gitignore +2 -0
  174. data/test/rails/app-1.2.3/Rakefile +7 -0
  175. data/test/rails/app-1.2.3/app/controllers/application.rb +6 -0
  176. data/test/rails/app-1.2.3/app/controllers/foo_controller.rb +36 -0
  177. data/test/rails/app-1.2.3/app/helpers/application_helper.rb +4 -0
  178. data/test/rails/app-1.2.3/config/boot.rb +11 -0
  179. data/test/rails/app-1.2.3/config/database.yml +12 -0
  180. data/test/rails/app-1.2.3/config/environment.rb +13 -0
  181. data/test/rails/app-1.2.3/config/environments/development.rb +9 -0
  182. data/test/rails/app-1.2.3/config/environments/production.rb +5 -0
  183. data/test/rails/app-1.2.3/config/routes.rb +6 -0
  184. data/test/rails/app-1.2.3/db/.gitignore +0 -0
  185. data/test/rails/app-1.2.3/public/404.html +1 -0
  186. data/test/rails/app-1.2.3/public/500.html +1 -0
  187. data/test/rails/app-2.0.2/.gitignore +2 -0
  188. data/test/rails/app-2.0.2/Rakefile +7 -0
  189. data/test/rails/app-2.0.2/app/controllers/application.rb +4 -0
  190. data/test/rails/app-2.0.2/app/controllers/foo_controller.rb +36 -0
  191. data/test/rails/app-2.0.2/app/helpers/application_helper.rb +4 -0
  192. data/test/rails/app-2.0.2/config/boot.rb +11 -0
  193. data/test/rails/app-2.0.2/config/database.yml +12 -0
  194. data/test/rails/app-2.0.2/config/environment.rb +17 -0
  195. data/test/rails/app-2.0.2/config/environments/development.rb +8 -0
  196. data/test/rails/app-2.0.2/config/environments/production.rb +5 -0
  197. data/test/rails/app-2.0.2/config/routes.rb +6 -0
  198. data/test/rails/app-2.0.2/db/.gitignore +0 -0
  199. data/test/rails/app-2.0.2/public/404.html +1 -0
  200. data/test/rails/app-2.0.2/public/500.html +1 -0
  201. data/test/rails/app-2.1.2/.gitignore +2 -0
  202. data/test/rails/app-2.1.2/Rakefile +7 -0
  203. data/test/rails/app-2.1.2/app/controllers/application.rb +4 -0
  204. data/test/rails/app-2.1.2/app/controllers/foo_controller.rb +36 -0
  205. data/test/rails/app-2.1.2/app/helpers/application_helper.rb +4 -0
  206. data/test/rails/app-2.1.2/config/boot.rb +111 -0
  207. data/test/rails/app-2.1.2/config/database.yml +12 -0
  208. data/test/rails/app-2.1.2/config/environment.rb +17 -0
  209. data/test/rails/app-2.1.2/config/environments/development.rb +7 -0
  210. data/test/rails/app-2.1.2/config/environments/production.rb +5 -0
  211. data/test/rails/app-2.1.2/config/routes.rb +6 -0
  212. data/test/rails/app-2.1.2/db/.gitignore +0 -0
  213. data/test/rails/app-2.1.2/public/404.html +1 -0
  214. data/test/rails/app-2.1.2/public/500.html +1 -0
  215. data/test/rails/app-2.2.2/.gitignore +2 -0
  216. data/test/rails/app-2.2.2/Rakefile +7 -0
  217. data/test/rails/app-2.2.2/app/controllers/application.rb +4 -0
  218. data/test/rails/app-2.2.2/app/controllers/foo_controller.rb +36 -0
  219. data/test/rails/app-2.2.2/app/helpers/application_helper.rb +4 -0
  220. data/test/rails/app-2.2.2/config/boot.rb +111 -0
  221. data/test/rails/app-2.2.2/config/database.yml +12 -0
  222. data/test/rails/app-2.2.2/config/environment.rb +17 -0
  223. data/test/rails/app-2.2.2/config/environments/development.rb +7 -0
  224. data/test/rails/app-2.2.2/config/environments/production.rb +5 -0
  225. data/test/rails/app-2.2.2/config/routes.rb +6 -0
  226. data/test/rails/app-2.2.2/db/.gitignore +0 -0
  227. data/test/rails/app-2.2.2/public/404.html +1 -0
  228. data/test/rails/app-2.2.2/public/500.html +1 -0
  229. data/test/rails/test_rails.rb +287 -0
  230. data/test/test_helper.rb +300 -0
  231. data/test/unit/test_configurator.rb +158 -0
  232. data/test/unit/test_droplet.rb +28 -0
  233. data/test/unit/test_http_parser.rb +860 -0
  234. data/test/unit/test_http_parser_ng.rb +716 -0
  235. data/test/unit/test_http_parser_xftrust.rb +38 -0
  236. data/test/unit/test_request.rb +197 -0
  237. data/test/unit/test_response.rb +99 -0
  238. data/test/unit/test_server.rb +289 -0
  239. data/test/unit/test_signals.rb +207 -0
  240. data/test/unit/test_sni_hostnames.rb +47 -0
  241. data/test/unit/test_socket_helper.rb +192 -0
  242. data/test/unit/test_stream_input.rb +204 -0
  243. data/test/unit/test_tee_input.rb +296 -0
  244. data/test/unit/test_upload.rb +306 -0
  245. data/test/unit/test_util.rb +100 -0
  246. data/unicorn-heroku.gemspec +44 -0
  247. metadata +426 -0
@@ -0,0 +1,5 @@
1
+ /random_blob
2
+ /.dep+*
3
+ /*.crt
4
+ /*.key
5
+ /ssl-stamp
@@ -0,0 +1,82 @@
1
+ # we can run tests in parallel with GNU make
2
+ all::
3
+
4
+ pid := $(shell echo $$PPID)
5
+
6
+ RUBY = ruby
7
+ RAKE = rake
8
+ -include ../local.mk
9
+ ifeq ($(RUBY_VERSION),)
10
+ RUBY_VERSION := $(shell $(RUBY) -e 'puts RUBY_VERSION')
11
+ endif
12
+
13
+ ifeq ($(RUBY_VERSION),)
14
+ $(error unable to detect RUBY_VERSION)
15
+ endif
16
+
17
+ RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
18
+ export RUBY_ENGINE
19
+
20
+ isolate_libs := ../tmp/isolate/$(RUBY_ENGINE)-$(RUBY_VERSION).mk
21
+ $(isolate_libs): ../script/isolate_for_tests
22
+ @cd .. && $(RUBY) script/isolate_for_tests
23
+ -include $(isolate_libs)
24
+ MYLIBS := $(RUBYLIB):$(ISOLATE_LIBS)
25
+
26
+ T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
27
+
28
+ all:: $(T)
29
+
30
+ # can't rely on "set -o pipefail" since we don't require bash or ksh93 :<
31
+ t_pfx = trash/$@-$(RUBY_ENGINE)-$(RUBY_VERSION)
32
+ TEST_OPTS =
33
+ # TRACER = strace -f -o $(t_pfx).strace -s 100000
34
+ # TRACER = /usr/bin/time -o $(t_pfx).time
35
+
36
+ ifdef V
37
+ ifeq ($(V),2)
38
+ TEST_OPTS += --trace
39
+ else
40
+ TEST_OPTS += --verbose
41
+ endif
42
+ endif
43
+
44
+ random_blob:
45
+ dd if=/dev/urandom bs=1M count=30 of=$@.$(pid)
46
+ mv $@.$(pid) $@
47
+
48
+ ssl-stamp:
49
+ ./sslgen.sh
50
+ > $@
51
+
52
+ $(T): random_blob ssl-stamp
53
+
54
+ dependencies := socat curl
55
+ deps := $(addprefix .dep+,$(dependencies))
56
+ $(deps): dep_bin = $(lastword $(subst +, ,$@))
57
+ $(deps):
58
+ @which $(dep_bin) > $@.$(pid) 2>/dev/null || :
59
+ @test -s $@.$(pid) || \
60
+ { echo >&2 "E '$(dep_bin)' not found in PATH=$(PATH)"; exit 1; }
61
+ @mv $@.$(pid) $@
62
+ dep: $(deps)
63
+
64
+ test_prefix := $(CURDIR)/../test/$(RUBY_ENGINE)-$(RUBY_VERSION)
65
+ $(test_prefix)/.stamp:
66
+ $(MAKE) -C .. test-install
67
+
68
+ $(T): export RUBY := $(RUBY)
69
+ $(T): export RAKE := $(RAKE)
70
+ $(T): export PATH := $(test_prefix)/bin:$(PATH)
71
+ $(T): export RUBYLIB := $(test_prefix)/lib:$(MYLIBS)
72
+ $(T): dep $(test_prefix)/.stamp trash/.gitignore
73
+ $(TRACER) $(SHELL) $(SH_TEST_OPTS) $@ $(TEST_OPTS)
74
+
75
+ trash/.gitignore:
76
+ mkdir -p $(@D)
77
+ echo '*' > $@
78
+
79
+ clean:
80
+ $(RM) -r trash/*
81
+
82
+ .PHONY: $(T) clean
@@ -0,0 +1,42 @@
1
+ = Unicorn integration test suite
2
+
3
+ These are all integration tests that start the server on random, unused
4
+ TCP ports or Unix domain sockets. They're all designed to run
5
+ concurrently with other tests to minimize test time, but tests may be
6
+ run independently as well.
7
+
8
+ We write our tests in Bourne shell because that's what we're
9
+ comfortable writing integration tests with.
10
+
11
+ == Requirements
12
+
13
+ * {Ruby 1.8 or 1.9}[http://www.ruby-lang.org/] (duh!)
14
+ * {GNU make}[http://www.gnu.org/software/make/]
15
+ * {socat}[http://www.dest-unreach.org/socat/]
16
+ * {curl}[http://curl.haxx.se/]
17
+ * standard UNIX shell utilities (Bourne sh, awk, sed, grep, ...)
18
+
19
+ We do not use bashisms or any non-portable, non-POSIX constructs
20
+ in our shell code. We use the "pipefail" option if available and
21
+ mainly test with {ksh}[http://kornshell.com/], but occasionally
22
+ with {dash}[http://gondor.apana.org.au/~herbert/dash/] and
23
+ {bash}[http://www.gnu.org/software/bash/], too.
24
+
25
+ == Running Tests
26
+
27
+ To run the entire test suite with 8 tests running at once:
28
+
29
+ make -j8
30
+
31
+ To run one individual test:
32
+
33
+ make t0000-simple-http.sh
34
+
35
+ You may also increase verbosity by setting the "V" variable for
36
+ GNU make. To disable trapping of stdout/stderr:
37
+
38
+ make V=1
39
+
40
+ To enable the "set -x" option in shell scripts to trace execution
41
+
42
+ make V=2
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: binary -*-
3
+ # simple chunked HTTP PUT request generator (and just that),
4
+ # it reads stdin and writes to stdout so socat can write to a
5
+ # UNIX or TCP socket (or to another filter or file) along with
6
+ # a Content-MD5 trailer.
7
+ require 'digest/md5'
8
+ $stdout.sync = $stderr.sync = true
9
+ $stdout.binmode
10
+ $stdin.binmode
11
+
12
+ bs = ENV['bs'] ? ENV['bs'].to_i : 4096
13
+
14
+ if ARGV.grep("--no-headers").empty?
15
+ $stdout.write(
16
+ "PUT / HTTP/1.1\r\n" \
17
+ "Host: example.com\r\n" \
18
+ "Transfer-Encoding: chunked\r\n" \
19
+ "Trailer: Content-MD5\r\n" \
20
+ "\r\n"
21
+ )
22
+ end
23
+
24
+ digest = Digest::MD5.new
25
+ if buf = $stdin.readpartial(bs)
26
+ begin
27
+ digest.update(buf)
28
+ $stdout.write("%x\r\n" % [ buf.size ])
29
+ $stdout.write(buf)
30
+ $stdout.write("\r\n")
31
+ end while $stdin.read(bs, buf)
32
+ end
33
+
34
+ digest = [ digest.digest ].pack('m').strip
35
+ $stdout.write("0\r\n")
36
+ $stdout.write("Content-MD5: #{digest}\r\n\r\n")
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: binary -*-
3
+ # Reads from stdin and outputs the SHA1 hex digest of the input
4
+
5
+ require 'digest/sha1'
6
+ $stdout.sync = $stderr.sync = true
7
+ $stdout.binmode
8
+ $stdin.binmode
9
+ bs = 16384
10
+ digest = Digest::SHA1.new
11
+ if buf = $stdin.read(bs)
12
+ begin
13
+ digest.update(buf)
14
+ end while $stdin.read(bs, buf)
15
+ end
16
+
17
+ $stdout.syswrite("#{digest.hexdigest}\n")
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: binary -*-
3
+ # this is to remain compatible with the unused_port function in the
4
+ # Unicorn test/test_helper.rb file
5
+ require 'socket'
6
+ require 'tmpdir'
7
+
8
+ default_port = 8080
9
+ addr = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1'
10
+ retries = 100
11
+ base = 5000
12
+ port = sock = lock_path = nil
13
+
14
+ begin
15
+ begin
16
+ port = base + rand(32768 - base)
17
+ while port == default_port
18
+ port = base + rand(32768 - base)
19
+ end
20
+
21
+ sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
22
+ sock.bind(Socket.pack_sockaddr_in(port, addr))
23
+ sock.listen(5)
24
+ rescue Errno::EADDRINUSE, Errno::EACCES
25
+ sock.close rescue nil
26
+ retry if (retries -= 1) >= 0
27
+ end
28
+
29
+ # since we'll end up closing the random port we just got, there's a race
30
+ # condition could allow the random port we just chose to reselect itself
31
+ # when running tests in parallel with gmake. Create a lock file while
32
+ # we have the port here to ensure that does not happen.
33
+ lock_path = "#{Dir::tmpdir}/unicorn_test.#{addr}:#{port}.lock"
34
+ lock = File.open(lock_path, File::WRONLY|File::CREAT|File::EXCL, 0600)
35
+ rescue Errno::EEXIST
36
+ sock.close rescue nil
37
+ retry
38
+ end
39
+ sock.close rescue nil
40
+ puts %Q(listen=#{addr}:#{port} T_RM_LIST="$T_RM_LIST #{lock_path}")
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: binary -*-
3
+ # tee(1) as distributed on most(all?) systems is buffered in luserspace
4
+ # this only does unbuffered writes (with line-buffered input) to make
5
+ # test output appear in real-time
6
+ $stdin.binmode
7
+ $stdout.binmode
8
+ fp = File.open(ARGV.shift, "wb")
9
+ $stdin.each_line do |line|
10
+ fp.syswrite line
11
+ $stdout.syswrite line
12
+ end
@@ -0,0 +1,12 @@
1
+ # we do not want Rack::Lint or anything to protect us
2
+ use Rack::ContentLength
3
+ use Rack::ContentType, "text/plain"
4
+ map "/" do
5
+ run lambda { |env| [ 200, {}, [ "OK\n" ] ] }
6
+ end
7
+ map "/raise" do
8
+ run lambda { |env| raise "BAD" }
9
+ end
10
+ map "/nil" do
11
+ run lambda { |env| nil }
12
+ end
@@ -0,0 +1,11 @@
1
+ use Rack::ContentType, "text/plain"
2
+ fifo_path = ENV["TEST_FIFO"] or abort "TEST_FIFO not set"
3
+ run lambda { |env|
4
+ pid = fork do
5
+ File.open(fifo_path, "wb") do |fp|
6
+ fp.write "HIHI"
7
+ end
8
+ end
9
+ Process.detach(pid)
10
+ [ 200, {}, [ pid.to_s ] ]
11
+ }
@@ -0,0 +1,3 @@
1
+ use Rack::ContentLength
2
+ use Rack::ContentType, "text/plain"
3
+ run lambda { |env| [ 200, {}, [ env.inspect << "\n" ] ] }
@@ -0,0 +1,12 @@
1
+ use Rack::ContentLength
2
+ headers = { 'Content-Type' => 'text/plain' }
3
+ run lambda { |env|
4
+ case env['PATH_INFO']
5
+ when "/block-forever"
6
+ Process.kill(:STOP, $$)
7
+ sleep # in case STOP signal is not received in time
8
+ [ 500, headers, [ "Should never get here\n" ] ]
9
+ else
10
+ [ 200, headers, [ "#$$\n" ] ]
11
+ end
12
+ }
@@ -0,0 +1,201 @@
1
+ #!/bin/sh
2
+ # Copyright (c) 2009, 2010 Eric Wong <normalperson@yhbt.net>
3
+ #
4
+ # TAP-producing shell library for POSIX-compliant Bourne shells We do
5
+ # not _rely_ on Bourne Again features, though we will use "set -o
6
+ # pipefail" from ksh93 or bash 3 if available
7
+ #
8
+ # Only generic, non-project/non-language-specific stuff goes here. We
9
+ # only have POSIX dependencies for the core tests (without --verbose),
10
+ # though we'll enable useful non-POSIX things if they're available.
11
+ #
12
+ # This test library is intentionally unforgiving, it does not support
13
+ # skipping tests nor continuing after any failure. Any failures
14
+ # immediately halt execution as do any references to undefined
15
+ # variables.
16
+ #
17
+ # When --verbose is specified, we always prefix stdout/stderr
18
+ # output with "#" to avoid confusing TAP consumers. Otherwise
19
+ # the normal stdout/stderr streams are redirected to /dev/null
20
+
21
+ # dup normal stdout(fd=1) and stderr (fd=2) to fd=3 and fd=4 respectively
22
+ # normal TAP output goes to fd=3, nothing should go to fd=4
23
+ exec 3>&1 4>&2
24
+
25
+ # ensure a sane environment
26
+ TZ=UTC LC_ALL=C LANG=C
27
+ export LANG LC_ALL TZ
28
+ unset CDPATH
29
+
30
+ # pipefail is non-POSIX, but very useful in ksh93/bash
31
+ ( set -o pipefail 2>/dev/null ) && set -o pipefail
32
+
33
+ SED=${SED-sed}
34
+
35
+ # Unlike other test frameworks, we are unforgiving and bail immediately
36
+ # on any failures. We do this because we're lazy about error handling
37
+ # and also because we believe anything broken should not be allowed to
38
+ # propagate throughout the rest of the test
39
+ set -e
40
+ set -u
41
+
42
+ # name of our test
43
+ T=${0##*/}
44
+
45
+ t_expect_nr=-1
46
+ t_nr=0
47
+ t_current=
48
+ t_complete=false
49
+
50
+ # list of files to remove unconditionally on exit
51
+ T_RM_LIST=
52
+
53
+ # list of files to remove only on successful exit
54
+ T_OK_RM_LIST=
55
+
56
+ # emit output to stdout, it'll be parsed by the TAP consumer
57
+ # so it must be TAP-compliant output
58
+ t_echo () {
59
+ echo >&3 "$@"
60
+ }
61
+
62
+ # emits non-parsed information to stdout, it will be prefixed with a '#'
63
+ # to not throw off TAP consumers
64
+ t_info () {
65
+ t_echo '#' "$@"
66
+ }
67
+
68
+ # exit with an error and print a diagnostic
69
+ die () {
70
+ echo >&2 "$@"
71
+ exit 1
72
+ }
73
+
74
+ # our at_exit handler, it'll fire for all exits except SIGKILL (unavoidable)
75
+ t_at_exit () {
76
+ code=$?
77
+ set +e
78
+ if test $code -eq 0
79
+ then
80
+ $t_complete || {
81
+ t_info "t_done not called"
82
+ code=1
83
+ }
84
+ elif test -n "$t_current"
85
+ then
86
+ t_echo "not ok $t_nr - $t_current"
87
+ fi
88
+ if test $t_expect_nr -ne -1
89
+ then
90
+ test $t_expect_nr -eq $t_nr || {
91
+ t_info "planned $t_expect_nr tests but ran $t_nr"
92
+ test $code -ne 0 || code=1
93
+ }
94
+ fi
95
+ $t_complete || {
96
+ t_info "unexpected test failure"
97
+ test $code -ne 0 || code=1
98
+ }
99
+ rm -f $T_RM_LIST
100
+ test $code -eq 0 && rm -f $T_OK_RM_LIST
101
+ set +x
102
+ exec >&3 2>&4
103
+ t_close_fds
104
+ exit $code
105
+ }
106
+
107
+ # close test-specific extra file descriptors
108
+ t_close_fds () {
109
+ exec 3>&- 4>&-
110
+ }
111
+
112
+ # call this at the start of your test to specify the number of tests
113
+ # you plan to run
114
+ t_plan () {
115
+ test "$1" -ge 1 || die "must plan at least one test"
116
+ test $t_expect_nr -eq -1 || die "tried to plan twice in one test"
117
+ t_expect_nr=$1
118
+ shift
119
+ t_echo 1..$t_expect_nr "#" "$@"
120
+ trap t_at_exit EXIT
121
+ }
122
+
123
+ _t_checkup () {
124
+ test $t_expect_nr -le 0 && die "no tests planned"
125
+ test -n "$t_current" && t_echo "ok $t_nr - $t_current"
126
+ true
127
+ }
128
+
129
+ # finalizes any previously test and starts a new one
130
+ t_begin () {
131
+ _t_checkup
132
+ t_nr=$(( $t_nr + 1 ))
133
+ t_current="$1"
134
+
135
+ # just in case somebody wanted to cheat us:
136
+ set -e
137
+ }
138
+
139
+ # finalizes the current test without starting a new one
140
+ t_end () {
141
+ _t_checkup
142
+ t_current=
143
+ }
144
+
145
+ # run this to signify the end of your test
146
+ t_done () {
147
+ _t_checkup
148
+ t_current=
149
+ t_complete=true
150
+ test $t_expect_nr -eq $t_nr || exit 1
151
+ exit 0
152
+ }
153
+
154
+ # create and assign named-pipes to variable _names_ passed to this function
155
+ t_fifos () {
156
+ for _id in "$@"
157
+ do
158
+ _name=$_id
159
+ _tmp=$(mktemp -t $T.$$.$_id.XXXXXXXX)
160
+ eval "$_id=$_tmp"
161
+ rm -f $_tmp
162
+ mkfifo $_tmp
163
+ T_RM_LIST="$T_RM_LIST $_tmp"
164
+ done
165
+ }
166
+
167
+ t_verbose=false t_trace=false
168
+
169
+ while test "$#" -ne 0
170
+ do
171
+ arg="$1"
172
+ shift
173
+ case $arg in
174
+ -v|--verbose) t_verbose=true ;;
175
+ --trace) t_trace=true t_verbose=true ;;
176
+ *) die "Unknown option: $arg" ;;
177
+ esac
178
+ done
179
+
180
+ # we always only setup stdout, nothing should end up in the "real" stderr
181
+ if $t_verbose
182
+ then
183
+ if test x"$(which mktemp 2>/dev/null)" = x
184
+ then
185
+ die "mktemp(1) not available for --verbose"
186
+ fi
187
+ t_fifos t_stdout t_stderr
188
+
189
+ (
190
+ # use a subshell so seds are not waitable
191
+ $SED -e 's/^/#: /' < $t_stdout &
192
+ $SED -e 's/^/#! /' < $t_stderr &
193
+ ) &
194
+ wait
195
+ exec > $t_stdout 2> $t_stderr
196
+ else
197
+ exec > /dev/null 2> /dev/null
198
+ fi
199
+
200
+ $t_trace && set -x
201
+ true