Skip to content

Commit 7a09a4a

Browse files
committed
Slightly simplify _count_child_pids
1 parent 7cf6f3c commit 7a09a4a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

test/runtests.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,22 +408,24 @@ function _count_child_pids()
408408
if Sys.isunix() && !isnothing(Sys.which("ps"))
409409
pids = Int[]
410410
out = try
411+
# Suggested in <https://askubuntu.com/a/512872>.
411412
readchomp(`ps -o ppid= -o pid= -A`)
412413
catch
413414
return -1
414415
end
415416
lines = split(out, '\n')
417+
# The output of `ps` always contains `ps` itself because it's spawn by
418+
# the current process, so we subtract one to always exclude it.
419+
count = -1
416420
for line in lines
417421
m = match(r" *(\d+) +(\d+)", line)
418422
if !isnothing(m)
419423
if parse(Int, m[1]) == pid
420-
push!(pids, parse(Int, m[2]))
424+
count += 1
421425
end
422426
end
423427
end
424-
# The output of `ps` always contains `ps` itself because it's spawn by
425-
# the current process, so we subtract one to always exclude it.
426-
return length(pids) - 1
428+
return count
427429
else
428430
return -1
429431
end
@@ -444,11 +446,12 @@ end
444446
before = _count_child_pids()
445447
if before < 0
446448
# Counting child PIDs not supported on this platform
447-
@test_broken false
449+
@test_skip false
448450
else
449451
old_id_counter = ParallelTestRunner.ID_COUNTER[]
450452
njobs = 2
451453
runtests(ParallelTestRunner, ["--jobs=$(njobs)", "--verbose"]; testsuite, stdout=devnull, stderr=devnull)
454+
# Make sure we didn't spawn more workers than expected.
452455
@test ParallelTestRunner.ID_COUNTER[] == old_id_counter + njobs
453456
# Allow a moment for worker processes to exit
454457
for _ in 1:50

0 commit comments

Comments
 (0)