1 # -*- encoding: binary -*-
2 require "./test/rack_unicorn"
3 $stderr.sync = $stdout.sync = true
5 class TestMiddlewareUnicorn < Test::Unit::TestCase
8 @host = ENV["UNICORN_TEST_ADDR"] || "127.0.0.1"
9 sock = TCPServer.new @host, 0
11 ENV["UNICORN_FD"] = sock.fileno.to_s
12 @host_with_port = "#@host:#@port"
13 @opts = { :listeners => [ @host_with_port ] }
14 @addr_regexp = Regexp.escape @host_with_port
17 def test_auto_listener
18 @app = Rack::Builder.new do
19 use Raindrops::Middleware
22 @srv = fork { Unicorn.run(@app, @opts) }
24 s = TCPSocket.new @host, @port
25 s.write "GET /_raindrops HTTP/1.0\r\n\r\n"
27 head, body = resp.split /\r\n\r\n/, 2
28 assert_match %r{^#@addr_regexp active: 1$}, body
29 assert_match %r{^#@addr_regexp queued: 0$}, body
33 Process.kill :QUIT, @srv
34 _, status = Process.waitpid2 @srv
35 assert status.success?
37 end if defined?(Unicorn) && RUBY_PLATFORM =~ /linux/