Skip to content

Commit fc403a9

Browse files
authored
Merge pull request #71 from JuliaWeb/caf/fix-test-conn-cleanup
This fixes various alarming finalizer errors when running the tests - in those cases, sockets appear to have been closed before the finalizer gets to run. Also make sure to run the test RemoteREPL server processes in the Julia environment set up by the test runner. Fix #70
2 parents e4b08e2 + d9f26aa commit fc403a9

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

test/runtests.jl

+20-7
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ function wait_conn(host, port, use_ssh; max_tries=4, session_id=nothing)
6868
for i=1:max_tries
6969
try
7070
return RemoteREPL.Connection(host=host, port=port,
71-
tunnel=use_ssh ? :ssh : :none,
72-
ssh_opts=`-o StrictHostKeyChecking=no`,
73-
session_id=session_id)
71+
tunnel=use_ssh ? :ssh : :none,
72+
ssh_opts=`-o StrictHostKeyChecking=no`,
73+
session_id=session_id)
7474
catch exc
7575
if i == max_tries
7676
rethrow()
@@ -112,9 +112,13 @@ if !use_ssh
112112
end
113113
@info use_ssh ? "Running tests with SSH tunnel" : "Testing without SSH tunnel - localhost only"
114114

115+
test_project = Base.active_project()
116+
117+
let
115118
# Use non-default port to avoid clashes with concurrent interactive use or testing.
116119
test_port = RemoteREPL.find_free_port(Sockets.localhost)
117-
server_proc = run(`$(Base.julia_cmd()) --project -e "using RemoteREPL, Sockets, UUIDs ; serve_repl($test_port)"`, wait=false)
120+
server_proc = run(`$(Base.julia_cmd()) --project=$test_project -e "using RemoteREPL, Sockets, UUIDs ; serve_repl($test_port)"`, wait=false)
121+
conn = nothing
118122

119123
try
120124

@@ -297,18 +301,23 @@ try
297301
end
298302

299303
finally
304+
!isnothing(conn) && close(conn)
300305
kill(server_proc)
301306
end
307+
end
302308

303-
309+
let
304310
test_port = RemoteREPL.find_free_port(Sockets.localhost)
305-
server_proc = run(```$(Base.julia_cmd()) --project -e "using RemoteREPL, Sockets, UUIDs ; module EvalInMod ; end;
311+
server_proc = run(```$(Base.julia_cmd()) --project=$test_project -e "using RemoteREPL, Sockets, UUIDs ; module EvalInMod ; end;
306312
serve_repl($test_port, on_client_connect=sess->sess.in_module=EvalInMod)"```, wait=false)
313+
conn = nothing
314+
conn2 = nothing
315+
conn3 = nothing
316+
307317
try
308318

309319
@testset "on_client_connect" begin
310320
conn = wait_conn(test_interface, test_port, use_ssh)
311-
312321
runcommand(cmdstr) = runcommand_unwrap(conn, cmdstr)
313322

314323
@test runcommand("@__MODULE__") == "Main.EvalInMod"
@@ -326,7 +335,11 @@ try
326335
end
327336

328337
finally
338+
!isnothing(conn) && close(conn)
339+
!isnothing(conn2) && close(conn2)
340+
!isnothing(conn3) && close(conn3)
329341
kill(server_proc)
330342
end
343+
end
331344

332345
nothing

0 commit comments

Comments
 (0)