about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorBrian Corrigan <brian@genexp.me>2012-06-05 11:46:34 -0400
committerEric Wong <normalperson@yhbt.net>2012-06-05 17:16:38 -0700
commit15dea14dd4e1af97aef928430c3c8ef8c5d74451 (patch)
tree4f0af6016b8ee1914f9a41933c9ea391c8649a24 /test
parent3a7387205dd5791a443215ae6b365865e0eacfa3 (diff)
downloadraindrops-15dea14dd4e1af97aef928430c3c8ef8c5d74451.tar.gz
Raindrops currently fails when provided a symlink to a socket.
As this is a common practice for many deployment tools (Vlad,
etc.) this patch adds support for finding the realpath prior to
looking the socket up in /proc/net/unix

[ew: commit message subject]

[ew: fixed test to pass under 1.9.3 and 1.8.7:
* Tempfile#unlink is unsafe to call if we want to reuse the
  path, use File.unlink(tmp.path) instead

* The return value of File.symlink is zero (or it raises),
  so it's unusable.

* File.symlink will not call #to_path under 1.8.7, so it's
  necessary to pass pathnames to it, not Tempfile objects.
]

Signed-off-by: Eric Wong <normalperson@yhbt.net>
Diffstat (limited to 'test')
-rw-r--r--test/test_linux.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/test_linux.rb b/test/test_linux.rb
index 65f25e0..81463c9 100644
--- a/test/test_linux.rb
+++ b/test/test_linux.rb
@@ -67,6 +67,32 @@ class TestLinux < Test::Unit::TestCase
     assert_equal 1, stats[tmp.path].queued
   end
 
+  def test_unix_resolves_symlinks
+    tmp = Tempfile.new("\xde\xad\xbe\xef") # valid path, really :)
+    File.unlink(tmp.path)
+    us = UNIXServer.new(tmp.path)
+
+    # Create a symlink
+    destination = Tempfile.new("somethingelse")
+    destination.unlink # We need an available name, not an actual file
+    link = File.symlink(tmp, destination)
+
+    @to_close << UNIXSocket.new(tmp.path)
+    stats = unix_listener_stats
+    assert_equal 0, stats[link.path].active
+    assert_equal 1, stats[link.path].queued
+
+    @to_close << UNIXSocket.new(tmp.path)
+    stats = unix_listener_stats
+    assert_equal 0, stats[link.path].active
+    assert_equal 2, stats[link.path].queued
+
+    @to_close << us.accept
+    stats = unix_listener_stats
+    assert_equal 1, stats[link.path].active
+    assert_equal 1, stats[link.path].queued
+  end
+
   def test_tcp
     s = TCPServer.new(TEST_ADDR, 0)
     port = s.addr[1]