From b94c20ee8d2bc3fea90cd9133d588c58859d6bf8 Mon Sep 17 00:00:00 2001 From: Amit Murthy Date: Mon, 22 May 2017 21:17:58 +0530 Subject: [PATCH] Return socket correctly in socket_reuse_port (#22017) * Return socket correctly in socket_reuse_port * Run reuseport tests only if SO_REUSEPORT is supported. * Test fix - test for successful addition of workers in distributed test (cherry picked from commit d3bc3295b4596ed5ed916379cdd8d9cab5e49a02) --- base/distributed/managers.jl | 1 + test/distributed_exec.jl | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/base/distributed/managers.jl b/base/distributed/managers.jl index 2bd4ceceab952..66753ee09be6d 100644 --- a/base/distributed/managers.jl +++ b/base/distributed/managers.jl @@ -472,6 +472,7 @@ function socket_reuse_port() return TCPSocket() end is_apple() && bind_client_port(s) + return s else return TCPSocket() end diff --git a/test/distributed_exec.jl b/test/distributed_exec.jl index bc9e58e28a596..3f12f5cb15075 100644 --- a/test/distributed_exec.jl +++ b/test/distributed_exec.jl @@ -11,10 +11,9 @@ include("testenv.jl") end addprocs_with_testenv(4) +@test nprocs() == 5 -# Test that the client port is reused. SO_REUSEPORT may not be supported on -# all UNIX platforms, Linux kernels prior to 3.9 and older versions of OSX -if is_unix() +function reuseport_tests() # Run the test on all processes. results = asyncmap(procs()) do p remotecall_fetch(p) do @@ -47,6 +46,19 @@ if is_unix() @test all(p -> p in results, procs()) end +# Test that the client port is reused. SO_REUSEPORT may not be supported on +# all UNIX platforms, Linux kernels prior to 3.9 and older versions of OSX +if is_unix() + # Run reuse client port tests only if SO_REUSEPORT is supported. + s = TCPSocket(delay = false) + is_linux() && Base.Distributed.bind_client_port(s) + if ccall(:jl_tcp_reuseport, Int32, (Ptr{Void},), s.handle) == 0 + reuseport_tests() + else + info("SO_REUSEPORT is unsupported, skipping reuseport tests.") + end +end + id_me = myid() id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]