raindrops.git  about / heads / tags
real-time stats for preforking Rack servers
blob 99ecb7fd81b054af9493167b5580d0729057e099 1138 bytes (raw)
$ git show HEAD:test/test_middleware_unicorn_ipv6.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
# -*- encoding: binary -*-
# frozen_string_literal: false
require "./test/rack_unicorn"
require "./test/ipv6_enabled"
$stderr.sync = $stdout.sync = true

class TestMiddlewareUnicornIPv6 < Test::Unit::TestCase

  def setup
    @host = ENV["TEST_HOST6"] || "::1"
    sock = TCPServer.new @host, 0
    @port = sock.addr[1]
    ENV["UNICORN_FD"] = sock.fileno.to_s
    @host_with_port = "[#@host]:#@port"
    @opts = { :listeners => [ @host_with_port ] }
    @addr_regexp = Regexp.escape @host_with_port
  end

  def test_auto_listener
    @app = Rack::Builder.new do
      use Raindrops::Middleware
      run Rack::Lobster.new
    end
    @srv = fork { Unicorn::HttpServer.new(@app, @opts).start.join }
    s = TCPSocket.new @host, @port
    s.write "GET /_raindrops HTTP/1.0\r\n\r\n"
    resp = s.read
    _, body = resp.split(/\r\n\r\n/, 2)
    assert_match %r{^#@addr_regexp active: 1$}, body
    assert_match %r{^#@addr_regexp queued: 0$}, body
  end

  def teardown
    Process.kill :QUIT, @srv
    _, status = Process.waitpid2 @srv
    assert status.success?
  end
end if defined?(Unicorn) && RUBY_PLATFORM =~ /linux/ && ipv6_enabled?

git clone https://yhbt.net/raindrops.git