last_data_recv: do not assume Unicorn includes all constants
[raindrops.git] / test / test_middleware_unicorn.rb
blob6730d4b3f61a0ce0ebf6bd94a4521681e770f905
1 # -*- encoding: binary -*-
2 require "./test/rack_unicorn"
3 $stderr.sync = $stdout.sync = true
5 class TestMiddlewareUnicorn < Test::Unit::TestCase
7   def setup
8     @host = ENV["UNICORN_TEST_ADDR"] || "127.0.0.1"
9     @sock = TCPServer.new @host, 0
10     @port = @sock.addr[1]
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
15   end
17   def test_auto_listener
18     @app = Rack::Builder.new do
19       use Raindrops::Middleware
20       run Rack::Lobster.new
21     end
22     @srv = fork { Unicorn::HttpServer.new(@app, @opts).start.join }
24     s = TCPSocket.new @host, @port
25     s.write "GET /_raindrops HTTP/1.0\r\n\r\n"
26     resp = s.read
27     _, 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
30   end
32   def teardown
33     Process.kill :QUIT, @srv
34     _, status = Process.waitpid2 @srv
35     assert status.success?
36   end
37 end if defined?(Unicorn) && RUBY_PLATFORM =~ /linux/