about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-03-12 12:56:15 -0800
committerEric Wong <normalperson@yhbt.net>2011-03-12 20:56:50 +0000
commitc478549ea7490de2432ed31ffee37a2bfc1d24f3 (patch)
treec4998b538dbfe13840bb527952e689c6d213d5c7 /test
parenta4b9c8334e2bc0698f0650d275be0935e86dc13e (diff)
downloadraindrops-c478549ea7490de2432ed31ffee37a2bfc1d24f3.tar.gz
No need to waste resources on creating/destroying
a socket.
Diffstat (limited to 'test')
-rw-r--r--test/test_inet_diag_socket.rb13
-rw-r--r--test/test_linux.rb26
2 files changed, 39 insertions, 0 deletions
diff --git a/test/test_inet_diag_socket.rb b/test/test_inet_diag_socket.rb
new file mode 100644
index 0000000..c40d50e
--- /dev/null
+++ b/test/test_inet_diag_socket.rb
@@ -0,0 +1,13 @@
+# -*- encoding: binary -*-
+require 'test/unit'
+require 'raindrops'
+$stderr.sync = $stdout.sync = true
+
+class TestInetDiagSocket < Test::Unit::TestCase
+  def test_new
+    sock = Raindrops::InetDiagSocket.new
+    assert_kind_of Socket, sock
+    assert_kind_of Fixnum, sock.fileno
+    assert_nil sock.close
+  end
+end if RUBY_PLATFORM =~ /linux/
diff --git a/test/test_linux.rb b/test/test_linux.rb
index 5a7269d..d3c8da7 100644
--- a/test/test_linux.rb
+++ b/test/test_linux.rb
@@ -62,6 +62,32 @@ class TestLinux < Test::Unit::TestCase
     assert_equal 1, stats[addr].active
   end
 
+  def test_tcp_reuse_sock
+    nlsock = Raindrops::InetDiagSocket.new
+    s = TCPServer.new(TEST_ADDR, 0)
+    port = s.addr[1]
+    addr = "#{TEST_ADDR}:#{port}"
+    addrs = [ addr ]
+    stats = tcp_listener_stats(addrs, nlsock)
+    assert_equal 1, stats.size
+    assert_equal 0, stats[addr].queued
+    assert_equal 0, stats[addr].active
+
+    c = TCPSocket.new(TEST_ADDR, port)
+    stats = tcp_listener_stats(addrs, nlsock)
+    assert_equal 1, stats.size
+    assert_equal 1, stats[addr].queued
+    assert_equal 0, stats[addr].active
+
+    sc = s.accept
+    stats = tcp_listener_stats(addrs, nlsock)
+    assert_equal 1, stats.size
+    assert_equal 0, stats[addr].queued
+    assert_equal 1, stats[addr].active
+    ensure
+      nlsock.close
+  end
+
   def test_tcp_multi
     s1 = TCPServer.new(TEST_ADDR, 0)
     s2 = TCPServer.new(TEST_ADDR, 0)