avoid warning for rb_thread_io_blocking_region
[raindrops.git] / test / test_linux_all_tcp_listen_stats.rb
blobef1f9431068a7946771a9496ca4c669a83dfa486
1 # -*- encoding: binary -*-
2 require 'test/unit'
3 require 'socket'
4 require 'raindrops'
5 require 'pp'
6 $stderr.sync = $stdout.sync = true
8 class TestLinuxAllTcpListenStats < Test::Unit::TestCase
9   include Raindrops::Linux
10   TEST_ADDR = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1'
12   def test_print_all
13     puts "EVERYTHING"
14     pp Raindrops::Linux.tcp_listener_stats
15     puts("-" * 72)
16   end if $stdout.tty?
18   def setup
19     @socks = []
20   end
22   def teardown
23     @socks.each { |io| io.closed? or io.close }
24   end
26   def new_server
27     s = TCPServer.new TEST_ADDR, 0
28     @socks << s
29     [ s, s.addr[1] ]
30   end
32   def new_client(port)
33     s = TCPSocket.new("127.0.0.1", port)
34     @socks << s
35     s
36   end
38   def new_accept(srv)
39     c = srv.accept
40     @socks << c
41     c
42   end
44   def test_all_ports
45     srv, port = new_server
46     addr = "#{TEST_ADDR}:#{port}"
47     all = Raindrops::Linux.tcp_listener_stats
48     assert_equal [0,0], all[addr].to_a
50     new_client(port)
51     all = Raindrops::Linux.tcp_listener_stats
52     assert_equal [0,1], all[addr].to_a
54     new_client(port)
55     all = Raindrops::Linux.tcp_listener_stats
56     assert_equal [0,2], all[addr].to_a
58     new_accept(srv)
59     all = Raindrops::Linux.tcp_listener_stats
60     assert_equal [1,1], all[addr].to_a
62     new_accept(srv)
63     all = Raindrops::Linux.tcp_listener_stats
64     assert_equal [2,0], all[addr].to_a
65   end
66 end if RUBY_PLATFORM =~ /linux/