Skip to content

Commit 3d77459

Browse files
committed
Use Lockable also for PTRWorker
1 parent 6867047 commit 3d77459

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

src/ParallelTestRunner.jl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@ const ID_COUNTER = Threads.Atomic{Int}(0)
4646
# Thin wrapper around Malt.Worker, to handle the stdio loop differently.
4747
struct PTRWorker <: Malt.AbstractWorker
4848
w::Malt.Worker
49-
io::IOBuffer
50-
io_lock::ReentrantLock
49+
io::Lockable{IOBuffer, ReentrantLock}
5150
id::Int
5251
end
5352

5453
function PTRWorker(; exename=Base.julia_cmd()[1], exeflags=String[], env=String[])
55-
io = IOBuffer()
56-
io_lock = ReentrantLock()
54+
io = Lockable(IOBuffer())
5755
wrkr = Malt.Worker(; exename, exeflags, env, monitor_stdout=false, monitor_stderr=false)
58-
stdio_loop(wrkr, io, io_lock)
56+
stdio_loop(wrkr, io)
5957
id = ID_COUNTER[] += 1
60-
return PTRWorker(wrkr, io, io_lock, id)
58+
return PTRWorker(wrkr, io, id)
6159
end
6260

6361
worker_id(wrkr::PTRWorker) = wrkr.id
@@ -311,19 +309,19 @@ function print_test_crashed(::Type{<:AbstractTestRecord}, wrkr, test, ctx::TestI
311309
end
312310

313311
# Adapted from `Malt._stdio_loop`
314-
function stdio_loop(worker::Malt.Worker, io, io_lock::ReentrantLock)
312+
function stdio_loop(worker::Malt.Worker, io::Lockable)
315313
Threads.@spawn while !eof(worker.stdout) && Malt.isrunning(worker)
316314
try
317315
bytes = readavailable(worker.stdout)
318-
@lock io_lock write(io, bytes)
316+
@lock io write(io[], bytes)
319317
catch
320318
break
321319
end
322320
end
323321
Threads.@spawn while !eof(worker.stderr) && Malt.isrunning(worker)
324322
try
325323
bytes = readavailable(worker.stderr)
326-
@lock io_lock write(io, bytes)
324+
@lock io write(io[], bytes)
327325
catch
328326
break
329327
end
@@ -1191,7 +1189,7 @@ function runtests(mod::Module, args::ParsedArgs;
11911189
ex
11921190
end
11931191
test_t1 = time()
1194-
output = Base.@lock wrkr.io_lock String(take!(wrkr.io))
1192+
output = @lock wrkr.io String(take!(wrkr.io[]))
11951193
@lock results push!(results[], (; test, result, output, test_t0, test_t1))
11961194

11971195
# act on the results

0 commit comments

Comments
 (0)