@@ -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
404- # Count direct child processes of current process (for default-worker test).
405- # Returns -1 if unsupported so the test can be skipped.
406- function _count_child_pids ()
407- pid = getpid ()
408- if Sys. isunix () && ! isnothing (Sys. which (" ps" ))
409- pids = Int[]
410- out = try
411- # Suggested in <https://askubuntu.com/a/512872>.
412- readchomp (` ps -o ppid= -o pid= -A` )
413- catch
414- return - 1
415- end
416- lines = split (out, ' \n ' )
417- # The output of `ps` always contains `ps` itself because it's spawned by
418- # the current process, so we subtract one to always exclude it.
419- count = - 1
420- for line in lines
421- m = match (r" *(\d +) +(\d +)" , line)
422- if ! isnothing (m)
423- if parse (Int, m[1 ]) == pid
424- count += 1
425- end
426- end
427- end
428- return count
429- else
430- return - 1
431- end
432- end
433406
434407# Issue <https://github.com/JuliaTesting/ParallelTestRunner.jl/issues/106>.
435408@testset " default workers stopped at end" begin
441414 " t3" => :(),
442415 " t4" => :(),
443416 " t5" => :(),
444- " t6" => :(),
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 ,
445428 )
446429 before = _count_child_pids ()
447430 if before < 0
450433 else
451434 old_id_counter = ParallelTestRunner. ID_COUNTER[]
452435 njobs = 2
453- runtests (ParallelTestRunner, [" --jobs=$(njobs) " , " --verbose" ]; testsuite, stdout = devnull , stderr = devnull )
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
454449 # Make sure we didn't spawn more workers than expected.
455450 @test ParallelTestRunner. ID_COUNTER[] == old_id_counter + njobs
456451 # Allow a moment for worker processes to exit
0 commit comments