Skip to content

Commit

Permalink
Merge pull request #71 from JuliaWeb/caf/fix-test-conn-cleanup
Browse files Browse the repository at this point in the history
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
  • Loading branch information
c42f authored Aug 1, 2024
2 parents e4b08e2 + d9f26aa commit fc403a9
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ function wait_conn(host, port, use_ssh; max_tries=4, session_id=nothing)
for i=1:max_tries
try
return RemoteREPL.Connection(host=host, port=port,
tunnel=use_ssh ? :ssh : :none,
ssh_opts=`-o StrictHostKeyChecking=no`,
session_id=session_id)
tunnel=use_ssh ? :ssh : :none,
ssh_opts=`-o StrictHostKeyChecking=no`,
session_id=session_id)
catch exc
if i == max_tries
rethrow()
Expand Down Expand Up @@ -112,9 +112,13 @@ if !use_ssh
end
@info use_ssh ? "Running tests with SSH tunnel" : "Testing without SSH tunnel - localhost only"

test_project = Base.active_project()

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

try

Expand Down Expand Up @@ -297,18 +301,23 @@ try
end

finally
!isnothing(conn) && close(conn)
kill(server_proc)
end
end


let
test_port = RemoteREPL.find_free_port(Sockets.localhost)
server_proc = run(```$(Base.julia_cmd()) --project -e "using RemoteREPL, Sockets, UUIDs ; module EvalInMod ; end;
server_proc = run(```$(Base.julia_cmd()) --project=$test_project -e "using RemoteREPL, Sockets, UUIDs ; module EvalInMod ; end;
serve_repl($test_port, on_client_connect=sess->sess.in_module=EvalInMod)"```, wait=false)
conn = nothing
conn2 = nothing
conn3 = nothing

try

@testset "on_client_connect" begin
conn = wait_conn(test_interface, test_port, use_ssh)

runcommand(cmdstr) = runcommand_unwrap(conn, cmdstr)

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

finally
!isnothing(conn) && close(conn)
!isnothing(conn2) && close(conn2)
!isnothing(conn3) && close(conn3)
kill(server_proc)
end
end

nothing

0 comments on commit fc403a9

Please sign in to comment.