@@ -3,6 +3,8 @@ using Test
33
44cd (@__DIR__ )
55
6+ include (joinpath (@__DIR__ , " utils.jl" ))
7+
68@testset " ParallelTestRunner" verbose= true begin
79
810@testset " basic use" begin
401403 @test ParallelTestRunner. ID_COUNTER[] == old_id_counter + njobs
402404end
403405
406+
407+ # Issue <https://github.com/JuliaTesting/ParallelTestRunner.jl/issues/106>.
408+ @testset " default workers stopped at end" begin
409+ # Use default workers (no test_worker) so the framework creates and should stop them.
410+ # More tests than workers so some tasks finish early and must stop their worker.
411+ testsuite = Dict (
412+ " t1" => :(),
413+ " t2" => :(),
414+ " t3" => :(),
415+ " t4" => :(),
416+ " t5" => :(),
417+ " t6" => quote
418+ # Make this test run longer than the others so that it runs alone...
419+ sleep (5 )
420+ children = _count_child_pids ($ (getpid ()))
421+ # ...then check there's only one worker still running. WARNING: this test may be
422+ # flaky on very busy systems, if at this point some of the other tests are still
423+ # running, hope for the best.
424+ if children >= 0
425+ @test children == 1
426+ end
427+ end ,
428+ )
429+ before = _count_child_pids ()
430+ if before < 0
431+ # Counting child PIDs not supported on this platform
432+ @test_skip false
433+ else
434+ old_id_counter = ParallelTestRunner. ID_COUNTER[]
435+ njobs = 2
436+ io = IOBuffer ()
437+ ioc = IOContext (io, :color => true )
438+ try
439+ runtests (ParallelTestRunner, [" --jobs=$(njobs) " , " --verbose" ];
440+ testsuite, stdout = ioc, stderr = ioc, init_code= :(include ($ (joinpath (@__DIR__ , " utils.jl" )))))
441+ catch
442+ # Show output in case of failure, to help debugging.
443+ output = String (take! (io))
444+ printstyled (stderr , " Output of failed test >>>>>>>>>>>>>>>>>>>>\n " , color= :red , bold= true )
445+ println (stderr , output)
446+ printstyled (stderr , " End of output <<<<<<<<<<<<<<<<<<<<<<<<<<<<\n " , color= :red , bold= true )
447+ rethrow ()
448+ end
449+ # Make sure we didn't spawn more workers than expected.
450+ @test ParallelTestRunner. ID_COUNTER[] == old_id_counter + njobs
451+ # Allow a moment for worker processes to exit
452+ for _ in 1 : 50
453+ sleep (0.1 )
454+ after = _count_child_pids ()
455+ after >= 0 && after <= before && break
456+ end
457+ after = _count_child_pids ()
458+ @test after >= 0
459+ @test after == before
460+ end
461+ end
462+
463+ # Custom workers are handled differently:
464+ # <https://github.com/JuliaTesting/ParallelTestRunner.jl/pull/107#issuecomment-3980645143>.
465+ # But we still want to make sure they're terminated at the end.
466+ @testset " custom workers stopped at end" begin
467+ testsuite = Dict (
468+ " a" => :(),
469+ " b" => :(),
470+ " c" => :(),
471+ " d" => :(),
472+ " e" => :(),
473+ " f" => :(),
474+ )
475+ procs = Base. Process[]
476+ procs_lock = ReentrantLock ()
477+ function test_worker (name)
478+ wrkr = addworker ()
479+ Base. @lock procs_lock push! (procs, wrkr. w. proc)
480+ return wrkr
481+ end
482+ runtests (ParallelTestRunner, Base. ARGS ; test_worker, testsuite, stdout = devnull , stderr = devnull )
483+ @test all (! Base. process_running, procs)
484+ end
485+
404486end
0 commit comments