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,8 +773,10 @@ 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
776- if Sys. isunix () # aka have ssh
778+ # LibSSH.jl currently only works on 64bit unixes
779+ if Sys. isunix () && Sys. WORD_SIZE == 64
777780 function test_n_remove_pids (new_pids)
778781 for p in new_pids
779782 w_in_remote = sort (remotecall_fetch (workers, p))
@@ -791,75 +794,78 @@ if Sys.isunix() # aka have ssh
791794 remotecall_fetch (rmprocs, 1 , new_pids)
792795 end
793796
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)
797+ println (" \n\n Testing SSHManager. A minimum of 4GB of RAM is recommended." )
798+ println (" Please ensure port 9300 and 2222 are not in use." )
799+
800+ DemoServer (2222 ; auth_methods= [ssh. AuthMethod_None], allow_auth_none= true , verbose= false , timeout= 3600 ) do
801+ sshflags = ` -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR -p 2222 `
802+ # Issue #9951
803+ hosts= []
804+ localhost_aliases = [" localhost" , string (getipaddr ()), " 127.0.0.1" ]
805+ num_workers = parse (Int,(get (ENV , " JULIA_ADDPROCS_NUM" , " 9" )))
806+
807+ for i in 1 : (num_workers/ length (localhost_aliases))
808+ append! (hosts, localhost_aliases)
858809 end
859- end
860810
811+ # CI machines sometimes don't already have a .ssh directory
812+ ssh_dir = joinpath (homedir (), " .ssh" )
813+ if ! isdir (ssh_dir)
814+ mkdir (ssh_dir)
815+ end
816+
817+ print (" \n Testing SSH addprocs with $(length (hosts)) workers...\n " )
818+ new_pids = addprocs_with_testenv (hosts; sshflags= sshflags)
819+ @test length (new_pids) == length (hosts)
820+ test_n_remove_pids (new_pids)
821+
822+ print (" \n Mixed ssh addprocs with :auto\n " )
823+ new_pids = addprocs_with_testenv ([" localhost" , (" 127.0.0.1" , :auto ), " localhost" ]; sshflags= sshflags)
824+ @test length (new_pids) == (2 + Sys. CPU_THREADS)
825+ test_n_remove_pids (new_pids)
826+
827+ print (" \n Mixed ssh addprocs with numeric counts\n " )
828+ new_pids = addprocs_with_testenv ([(" localhost" , 2 ), (" 127.0.0.1" , 2 ), " localhost" ]; sshflags= sshflags)
829+ @test length (new_pids) == 5
830+ test_n_remove_pids (new_pids)
831+
832+ print (" \n ssh addprocs with tunnel\n " )
833+ new_pids = addprocs_with_testenv ([(" localhost" , num_workers)]; tunnel= true , sshflags= sshflags)
834+ @test length (new_pids) == num_workers
835+ test_n_remove_pids (new_pids)
836+
837+ print (" \n ssh addprocs with tunnel (SSH multiplexing)\n " )
838+ new_pids = addprocs_with_testenv ([(" localhost" , num_workers)]; tunnel= true , multiplex= true , sshflags= sshflags)
839+ @test length (new_pids) == num_workers
840+ controlpath = joinpath (ssh_dir, " julia-$(ENV [" USER" ]) @localhost:2222" )
841+ @test issocket (controlpath)
842+ test_n_remove_pids (new_pids)
843+ @test :ok == timedwait (()-> ! issocket (controlpath), 10.0 ; pollint= 0.5 )
844+
845+ print (" \n All supported formats for hostname\n " )
846+ h1 = " localhost"
847+ user = ENV [" USER" ]
848+ h2 = " $user @$h1 "
849+ h3 = " $h2 :2222"
850+ h4 = " $h3 $(string (getipaddr ())) "
851+ h5 = " $h4 :9300"
852+
853+ new_pids = addprocs_with_testenv ([h1, h2, h3, h4, h5]; sshflags= sshflags)
854+ @test length (new_pids) == 5
855+ test_n_remove_pids (new_pids)
856+
857+ print (" \n keyword arg exename\n " )
858+ for exename in [` $(joinpath (Sys. BINDIR, Base. julia_exename ())) ` , " $(joinpath (Sys. BINDIR, Base. julia_exename ())) " ]
859+ for addp_func in [()-> addprocs_with_testenv ([" localhost" ]; exename= exename, exeflags= test_exeflags, sshflags= sshflags),
860+ ()-> addprocs_with_testenv (1 ; exename= exename, exeflags= test_exeflags)]
861+
862+ local new_pids = addp_func ()
863+ @test length (new_pids) == 1
864+ test_n_remove_pids (new_pids)
865+ end
866+ end
867+ end
861868end # unix-only
862- end # full-test
863869
864870let t = @task 42
865871 schedule (t, ErrorException (" " ), error= true )
0 commit comments