README: update with extra disclaimer
[raindrops.git] / test / test_middleware_unicorn_ipv6.rb
blob99ecb7fd81b054af9493167b5580d0729057e099
1 # -*- encoding: binary -*-
2 # frozen_string_literal: false
3 require "./test/rack_unicorn"
4 require "./test/ipv6_enabled"
5 $stderr.sync = $stdout.sync = true
7 class TestMiddlewareUnicornIPv6 < Test::Unit::TestCase
9   def setup
10     @host = ENV["TEST_HOST6"] || "::1"
11     sock = TCPServer.new @host, 0
12     @port = sock.addr[1]
13     ENV["UNICORN_FD"] = sock.fileno.to_s
14     @host_with_port = "[#@host]:#@port"
15     @opts = { :listeners => [ @host_with_port ] }
16     @addr_regexp = Regexp.escape @host_with_port
17   end
19   def test_auto_listener
20     @app = Rack::Builder.new do
21       use Raindrops::Middleware
22       run Rack::Lobster.new
23     end
24     @srv = fork { Unicorn::HttpServer.new(@app, @opts).start.join }
25     s = TCPSocket.new @host, @port
26     s.write "GET /_raindrops HTTP/1.0\r\n\r\n"
27     resp = s.read
28     _, body = resp.split(/\r\n\r\n/, 2)
29     assert_match %r{^#@addr_regexp active: 1$}, body
30     assert_match %r{^#@addr_regexp queued: 0$}, body
31   end
33   def teardown
34     Process.kill :QUIT, @srv
35     _, status = Process.waitpid2 @srv
36     assert status.success?
37   end
38 end if defined?(Unicorn) && RUBY_PLATFORM =~ /linux/ && ipv6_enabled?