From a1aa5c97289df09a90831c4d9bf6e22ac351bdd8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 4 Nov 2013 18:28:46 +0000 Subject: tests: fix SO_REUSEPORT tests for old Linux and non-Linux On BSD-derived platforms the getsockopt true value may be any (>= 0) value, not just one as it is on Linux. Additionally, SO_REUSEPORT is only supported since Linux 3.9, so folks on older kernels may not have it available. We still define it for Linux since kernel upgrades are usually more common than glibc upgrades. Note: we will still raise an exception at runtime if a user explicitly requests :reuseport in their config and runs an older Linux kernel. Reported-by: Andrew Hobson --- test/unit/test_socket_helper.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unit/test_socket_helper.rb b/test/unit/test_socket_helper.rb index abc177b..8992757 100644 --- a/test/unit/test_socket_helper.rb +++ b/test/unit/test_socket_helper.rb @@ -190,6 +190,8 @@ class TestSocketHelper < Test::Unit::TestCase name = "#@test_addr:#{port}" sock = bind_listen(name, :reuseport => true) cur = sock.getsockopt(Socket::SOL_SOCKET, SO_REUSEPORT).unpack('i')[0] - assert_equal 1, cur - end if defined?(SO_REUSEPORT) + assert_operator cur, :>, 0 + rescue Errno::ENOPROTOOPT + # kernel does not support SO_REUSEPORT (older Linux) + end end -- cgit v1.2.3-24-ge0c7