diff options
author | Eric Wong <e@80x24.org> | 2017-03-16 03:16:51 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-03-17 22:39:11 +0000 |
commit | 17d57231c4d9d3dfb486b6d37b85d57e6065958e (patch) | |
tree | 2ddee320f6d3b11b1cbdf9f3c65c3c52e96bdd15 /test | |
parent | 8d9f163a159a1366a86ba166142b4f6f3fd38083 (diff) | |
download | raindrops-17d57231c4d9d3dfb486b6d37b85d57e6065958e.tar.gz |
Of course these fields are not portable between Linux and FreeBSD, but they should remain ABI-compatible for future versions of each OS. Tested on FreeBSD 10.3-RELEASE i386 TCP state names will be another problem...
Diffstat (limited to 'test')
-rw-r--r-- | test/test_tcp_info.rb (renamed from test/test_linux_tcp_info.rb) | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/test/test_linux_tcp_info.rb b/test/test_tcp_info.rb index c947211..15df087 100644 --- a/test/test_linux_tcp_info.rb +++ b/test/test_tcp_info.rb @@ -5,15 +5,15 @@ require 'raindrops' require 'socket' require 'pp' $stderr.sync = $stdout.sync = true -class TestLinuxTCP_Info < Test::Unit::TestCase +class TestTCP_Info < Test::Unit::TestCase TEST_ADDR = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1' # Linux kernel commit 5ee3afba88f5a79d0bff07ddd87af45919259f91 TCP_INFO_useful_listenq = `uname -r`.strip >= '2.6.24' - - def test_tcp_server + def test_tcp_server_unacked + return if RUBY_PLATFORM !~ /linux/ # unacked not implemented on others... s = TCPServer.new(TEST_ADDR, 0) rv = Raindrops::TCP_Info.new s c = TCPSocket.new TEST_ADDR, s.addr[1] @@ -29,10 +29,8 @@ class TestLinuxTCP_Info < Test::Unit::TestCase tmp.get!(s) assert_equal before, tmp.object_id - ensure - c.close if c - a.close if a - s.close + ensure + [ c, a, s ].compact.each(&:close) end def test_accessors @@ -42,12 +40,14 @@ class TestLinuxTCP_Info < Test::Unit::TestCase assert tcp_info_methods.size >= 32 tcp_info_methods.each do |m| next if m.to_sym == :get! + next if ! tmp.respond_to?(m) val = tmp.__send__ m assert_kind_of Integer, val assert val >= 0 end - ensure - s.close + assert tmp.respond_to?(:state), 'every OS knows about TCP state, right?' + ensure + s.close end def test_tcp_server_delayed @@ -65,4 +65,21 @@ class TestLinuxTCP_Info < Test::Unit::TestCase a.close if a s.close end -end if RUBY_PLATFORM =~ /linux/ + + def test_tcp_server_state_closed + s = TCPServer.new(TEST_ADDR, 0) + c = TCPSocket.new(TEST_ADDR, s.addr[1]) + i = Raindrops::TCP_Info.allocate + a = s.accept + i.get!(a) + state = i.state + c = c.close + sleep(0.01) # wait for kernel to update state + i.get!(a) + assert_not_equal state, i.state + ensure + s.close if s + c.close if c + a.close if a + end +end if defined? Raindrops::TCP_Info |