Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up connections before exit in tests #71

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading