33using Test, DistributedNext, Random, Serialization, Sockets
44import DistributedNext: launch, manage
55
6+ import LibSSH as ssh
7+ import LibSSH. Demo: DemoServer
8+
69@test cluster_cookie () isa String
710
811include (joinpath (Sys. BINDIR, " .." , " share" , " julia" , " test" , " testenv.jl" ))
@@ -743,11 +746,9 @@ finally
743746 DistributedNext. default_worker_pool! (wp_default)
744747end
745748
746- # The below block of tests are usually run only on local development systems, since:
747- # - tests which print errors
748- # - addprocs tests are memory intensive
749- # - ssh addprocs requires sshd to be running locally with passwordless login enabled.
750- # The test block is enabled by defining env JULIA_TESTFULL=1
749+ # The below block of tests are usually run only on local development systems,
750+ # since they print errors. The test block is enabled by defining env
751+ # JULIA_TESTFULL=1.
751752
752753DoFullTest = Base. get_bool_env (" JULIA_TESTFULL" , false )
753754
@@ -772,6 +773,7 @@ if DoFullTest
772773 end
773774 @test workers () == all_w
774775 @test all ([p == remotecall_fetch (myid, p) for p in all_w])
776+ end
775777
776778if Sys. isunix () # aka have ssh
777779 function test_n_remove_pids (new_pids)
@@ -791,75 +793,78 @@ if Sys.isunix() # aka have ssh
791793 remotecall_fetch (rmprocs, 1 , new_pids)
792794 end
793795
794- print (" \n\n Testing SSHManager. A minimum of 4GB of RAM is recommended.\n " )
795- print (" Please ensure: \n " )
796- print (" 1) sshd is running locally with passwordless login enabled.\n " )
797- print (" 2) Env variable USER is defined and is the ssh user.\n " )
798- print (" 3) Port 9300 is not in use.\n " )
799-
800- sshflags = ` -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR `
801- # Issue #9951
802- hosts= []
803- localhost_aliases = [" localhost" , string (getipaddr ()), " 127.0.0.1" ]
804- num_workers = parse (Int,(get (ENV , " JULIA_ADDPROCS_NUM" , " 9" )))
805-
806- for i in 1 : (num_workers/ length (localhost_aliases))
807- append! (hosts, localhost_aliases)
808- end
809-
810- print (" \n Testing SSH addprocs with $(length (hosts)) workers...\n " )
811- new_pids = addprocs_with_testenv (hosts; sshflags= sshflags)
812- @test length (new_pids) == length (hosts)
813- test_n_remove_pids (new_pids)
814-
815- print (" \n Mixed ssh addprocs with :auto\n " )
816- new_pids = addprocs_with_testenv ([" localhost" , (" 127.0.0.1" , :auto ), " localhost" ]; sshflags= sshflags)
817- @test length (new_pids) == (2 + Sys. CPU_THREADS)
818- test_n_remove_pids (new_pids)
819-
820- print (" \n Mixed ssh addprocs with numeric counts\n " )
821- new_pids = addprocs_with_testenv ([(" localhost" , 2 ), (" 127.0.0.1" , 2 ), " localhost" ]; sshflags= sshflags)
822- @test length (new_pids) == 5
823- test_n_remove_pids (new_pids)
824-
825- print (" \n ssh addprocs with tunnel\n " )
826- new_pids = addprocs_with_testenv ([(" localhost" , num_workers)]; tunnel= true , sshflags= sshflags)
827- @test length (new_pids) == num_workers
828- test_n_remove_pids (new_pids)
829-
830- print (" \n ssh addprocs with tunnel (SSH multiplexing)\n " )
831- new_pids = addprocs_with_testenv ([(" localhost" , num_workers)]; tunnel= true , multiplex= true , sshflags= sshflags)
832- @test length (new_pids) == num_workers
833- controlpath = joinpath (homedir (), " .ssh" , " julia-$(ENV [" USER" ]) @localhost:22" )
834- @test issocket (controlpath)
835- test_n_remove_pids (new_pids)
836- @test :ok == timedwait (()-> ! issocket (controlpath), 10.0 ; pollint= 0.5 )
837-
838- print (" \n All supported formats for hostname\n " )
839- h1 = " localhost"
840- user = ENV [" USER" ]
841- h2 = " $user @$h1 "
842- h3 = " $h2 :22"
843- h4 = " $h3 $(string (getipaddr ())) "
844- h5 = " $h4 :9300"
845-
846- new_pids = addprocs_with_testenv ([h1, h2, h3, h4, h5]; sshflags= sshflags)
847- @test length (new_pids) == 5
848- test_n_remove_pids (new_pids)
849-
850- print (" \n keyword arg exename\n " )
851- for exename in [` $(joinpath (Sys. BINDIR, Base. julia_exename ())) ` , " $(joinpath (Sys. BINDIR, Base. julia_exename ())) " ]
852- for addp_func in [()-> addprocs_with_testenv ([" localhost" ]; exename= exename, exeflags= test_exeflags, sshflags= sshflags),
853- ()-> addprocs_with_testenv (1 ; exename= exename, exeflags= test_exeflags)]
854-
855- local new_pids = addp_func ()
856- @test length (new_pids) == 1
857- test_n_remove_pids (new_pids)
796+ println (" \n\n Testing SSHManager. A minimum of 4GB of RAM is recommended." )
797+ println (" Please ensure port 9300 and 2222 are not in use." )
798+
799+ DemoServer (2222 ; auth_methods= [ssh. AuthMethod_None], allow_auth_none= true , verbose= false , timeout= 3600 ) do
800+ sshflags = ` -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR -p 2222 `
801+ # Issue #9951
802+ hosts= []
803+ localhost_aliases = [" localhost" , string (getipaddr ()), " 127.0.0.1" ]
804+ num_workers = parse (Int,(get (ENV , " JULIA_ADDPROCS_NUM" , " 9" )))
805+
806+ for i in 1 : (num_workers/ length (localhost_aliases))
807+ append! (hosts, localhost_aliases)
858808 end
859- end
860809
810+ # CI machines sometimes don't already have a .ssh directory
811+ ssh_dir = joinpath (homedir (), " .ssh" )
812+ if ! isdir (ssh_dir)
813+ mkdir (ssh_dir)
814+ end
815+
816+ print (" \n Testing SSH addprocs with $(length (hosts)) workers...\n " )
817+ new_pids = addprocs_with_testenv (hosts; sshflags= sshflags)
818+ @test length (new_pids) == length (hosts)
819+ test_n_remove_pids (new_pids)
820+
821+ print (" \n Mixed ssh addprocs with :auto\n " )
822+ new_pids = addprocs_with_testenv ([" localhost" , (" 127.0.0.1" , :auto ), " localhost" ]; sshflags= sshflags)
823+ @test length (new_pids) == (2 + Sys. CPU_THREADS)
824+ test_n_remove_pids (new_pids)
825+
826+ print (" \n Mixed ssh addprocs with numeric counts\n " )
827+ new_pids = addprocs_with_testenv ([(" localhost" , 2 ), (" 127.0.0.1" , 2 ), " localhost" ]; sshflags= sshflags)
828+ @test length (new_pids) == 5
829+ test_n_remove_pids (new_pids)
830+
831+ print (" \n ssh addprocs with tunnel\n " )
832+ new_pids = addprocs_with_testenv ([(" localhost" , num_workers)]; tunnel= true , sshflags= sshflags)
833+ @test length (new_pids) == num_workers
834+ test_n_remove_pids (new_pids)
835+
836+ print (" \n ssh addprocs with tunnel (SSH multiplexing)\n " )
837+ new_pids = addprocs_with_testenv ([(" localhost" , num_workers)]; tunnel= true , multiplex= true , sshflags= sshflags)
838+ @test length (new_pids) == num_workers
839+ controlpath = joinpath (ssh_dir, " julia-$(ENV [" USER" ]) @localhost:2222" )
840+ @test issocket (controlpath)
841+ test_n_remove_pids (new_pids)
842+ @test :ok == timedwait (()-> ! issocket (controlpath), 10.0 ; pollint= 0.5 )
843+
844+ print (" \n All supported formats for hostname\n " )
845+ h1 = " localhost"
846+ user = ENV [" USER" ]
847+ h2 = " $user @$h1 "
848+ h3 = " $h2 :2222"
849+ h4 = " $h3 $(string (getipaddr ())) "
850+ h5 = " $h4 :9300"
851+
852+ new_pids = addprocs_with_testenv ([h1, h2, h3, h4, h5]; sshflags= sshflags)
853+ @test length (new_pids) == 5
854+ test_n_remove_pids (new_pids)
855+
856+ print (" \n keyword arg exename\n " )
857+ for exename in [` $(joinpath (Sys. BINDIR, Base. julia_exename ())) ` , " $(joinpath (Sys. BINDIR, Base. julia_exename ())) " ]
858+ for addp_func in [()-> addprocs_with_testenv ([" localhost" ]; exename= exename, exeflags= test_exeflags, sshflags= sshflags),
859+ ()-> addprocs_with_testenv (1 ; exename= exename, exeflags= test_exeflags)]
860+
861+ local new_pids = addp_func ()
862+ @test length (new_pids) == 1
863+ test_n_remove_pids (new_pids)
864+ end
865+ end
866+ end
861867end # unix-only
862- end # full-test
863868
864869let t = @task 42
865870 schedule (t, ErrorException (" " ), error= true )
0 commit comments