Skip to content

Commit 6ac243d

Browse files
committed
Ensure that free ports are used in the SSHManager tests
1 parent a8796c3 commit 6ac243d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

test/sshmanager.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Test
22
using DistributedNext
3-
import Sockets: getipaddr
3+
import Sockets: getipaddr, listenany
44

55
import LibSSH as ssh
66
import LibSSH.Demo: DemoServer
@@ -26,8 +26,11 @@ function test_n_remove_pids(new_pids)
2626
end
2727

2828
@testset "SSHManager" begin
29-
DemoServer(2222; auth_methods=[ssh.AuthMethod_None], allow_auth_none=true, verbose=false, timeout=3600) do
30-
sshflags = `-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR -p 2222 `
29+
ssh_port, server = listenany(2222)
30+
close(server)
31+
32+
DemoServer(Int(ssh_port); auth_methods=[ssh.AuthMethod_None], allow_auth_none=true, verbose=false, timeout=3600) do
33+
sshflags = `-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR -p $(ssh_port)`
3134
#Issue #9951
3235
hosts=[]
3336
localhost_aliases = ["localhost", string(getipaddr()), "127.0.0.1"]
@@ -66,7 +69,7 @@ end
6669
print("\nssh addprocs with tunnel (SSH multiplexing)\n")
6770
new_pids = addprocs_with_testenv([("localhost", num_workers)]; tunnel=true, multiplex=true, sshflags=sshflags)
6871
@test length(new_pids) == num_workers
69-
controlpath = joinpath(ssh_dir, "julia-$(ENV["USER"])@localhost:2222")
72+
controlpath = joinpath(ssh_dir, "julia-$(ENV["USER"])@localhost:$(ssh_port)")
7073
@test issocket(controlpath)
7174
test_n_remove_pids(new_pids)
7275
@test :ok == timedwait(()->!issocket(controlpath), 10.0; pollint=0.5)
@@ -82,9 +85,11 @@ end
8285
h1 = "localhost"
8386
user = ENV["USER"]
8487
h2 = "$user@$h1"
85-
h3 = "$h2:2222"
88+
h3 = "$h2:$(ssh_port)"
8689
h4 = "$h3 $(string(getipaddr()))"
87-
h5 = "$h4:9300"
90+
(bind_port, server) = listenany(9300)
91+
close(server)
92+
h5 = "$h4:$(bind_port)"
8893

8994
new_pids = addprocs_with_testenv([h1, h2, h3, h4, h5]; sshflags=sshflags)
9095
@test length(new_pids) == 5

0 commit comments

Comments
 (0)