last_data_recv: do not assume Unicorn includes all constants
[raindrops.git] / test / test_middleware_unicorn_ipv6.rb
blob3d6862ce1a716edcc62647f2ae518147f521f9e4
1 # -*- encoding: binary -*-
2 require "./test/rack_unicorn"
3 require "./test/ipv6_enabled"
4 $stderr.sync = $stdout.sync = true
6 class TestMiddlewareUnicornIPv6 < Test::Unit::TestCase
8   def setup
9     @host = ENV["TEST_HOST6"] || "::1"
10     sock = TCPServer.new @host, 0
11     @port = sock.addr[1]
12     ENV["UNICORN_FD"] = sock.fileno.to_s
13     @host_with_port = "[#@host]:#@port"
14     @opts = { :listeners => [ @host_with_port ] }
15     @addr_regexp = Regexp.escape @host_with_port
16   end
18   def test_auto_listener
19     @app = Rack::Builder.new do
20       use Raindrops::Middleware
21       run Rack::Lobster.new
22     end
23     @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/ && ipv6_enabled?