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))]