Sha256: 0d882f8f0b523f827df170ba031c9d49c8beb0358a82d1967f6fb95d46443e29

Contents?: true

Size: 1.36 KB

Versions: 26

Compression:

Stored size: 1.36 KB

Contents

# -*- encoding: binary -*-
require 'test/unit'
require 'socket'
require 'raindrops'
require 'pp'
$stderr.sync = $stdout.sync = true

class TestLinuxAllTcpListenStats < Test::Unit::TestCase
  include Raindrops::Linux
  TEST_ADDR = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1'

  def test_print_all
    puts "EVERYTHING"
    pp Raindrops::Linux.tcp_listener_stats
    puts("-" * 72)
  end if $stdout.tty?

  def setup
    @socks = []
  end

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

  def new_server
    s = TCPServer.new TEST_ADDR, 0
    @socks << s
    [ s, s.addr[1] ]
  end

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

  def new_accept(srv)
    c = srv.accept
    @socks << c
    c
  end

  def test_all_ports
    srv, port = new_server
    addr = "#{TEST_ADDR}:#{port}"
    all = Raindrops::Linux.tcp_listener_stats
    assert_equal [0,0], all[addr].to_a

    new_client(port)
    all = Raindrops::Linux.tcp_listener_stats
    assert_equal [0,1], all[addr].to_a

    new_client(port)
    all = Raindrops::Linux.tcp_listener_stats
    assert_equal [0,2], all[addr].to_a

    new_accept(srv)
    all = Raindrops::Linux.tcp_listener_stats
    assert_equal [1,1], all[addr].to_a

    new_accept(srv)
    all = Raindrops::Linux.tcp_listener_stats
    assert_equal [2,0], all[addr].to_a
  end
end if RUBY_PLATFORM =~ /linux/

Version data entries

26 entries across 26 versions & 3 rubygems

Version Path
raindrops-maintained-0.21.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.20.1 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.20.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.19.2 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.19.1 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.19.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.18.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.17.0 test/test_linux_all_tcp_listen_stats.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/raindrops-0.16.0/test/test_linux_all_tcp_listen_stats.rb
raindrops-0.16.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.15.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.14.0.1.g8177 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.14.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.13.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.12.0.5.g821b test/test_linux_all_tcp_listen_stats.rb
raindrops-0.12.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.11.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.10.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.9.0 test/test_linux_all_tcp_listen_stats.rb
raindrops-0.8.1 test/test_linux_all_tcp_listen_stats.rb