raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
blob 73995ea54d552fdac21b16c6dc65e8937adeeffc 1240 bytes (raw)
name: test/test_linux_reuseport_tcp_listen_stats.rb 	 # note: path name is non-authoritative(*)

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
 
# -*- encoding: binary -*-
require "./test/rack_unicorn"
require 'test/unit'
require 'socket'
require 'raindrops'
$stderr.sync = $stdout.sync = true

class TestLinuxReuseportTcpListenStats < Test::Unit::TestCase
  include Raindrops::Linux
  include Unicorn::SocketHelper
  TEST_ADDR = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1'
  DEFAULT_BACKLOG = 10

  def setup
    @socks = []
  end

  def teardown
    @socks.each { |io| io.closed? or io.close }
  end

  def new_socket_server(**kwargs)
    s = new_tcp_server TEST_ADDR, kwargs[:port] || 0, kwargs
    s.listen(kwargs[:backlog] || DEFAULT_BACKLOG)
    @socks << s
    [ s, s.addr[1] ]
  end

  def new_client(port)
    s = TCPSocket.new("127.0.0.1", port)
    @socks << s
    s
  end

  def test_reuseport_queue_stats
    listeners = 10
    _, port = new_socket_server(reuseport: true)
    addr = "#{TEST_ADDR}:#{port}"
    (listeners - 1).times do
      new_socket_server(reuseport: true, port: port)
    end

    listeners.times do |i|
      all = Raindrops::Linux.tcp_listener_stats
      assert_equal [0, i], all[addr].to_a
      new_client(port)
      all = Raindrops::Linux.tcp_listener_stats
      assert_equal [0, i+1], all[addr].to_a
    end
  end
end if RUBY_PLATFORM =~ /linux/

debug log:

solving 73995ea ...
found 73995ea in https://yhbt.net/raindrops.git/

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).