Skip to content

Commit 1c24eeb

Browse files
test multithreaded logging
1 parent e331deb commit 1c24eeb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

stdlib/Logging/test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,14 @@ end
306306
@test isempty(undoc)
307307
end
308308

309+
@testset "thread safety" begin
310+
cmd = `$(Base.julia_cmd()) -t4 $(joinpath(@__DIR__, "threads_exec.jl"))`
311+
fname = tempname()
312+
f = open(fname, "w")
313+
redirect_stderr(f) do
314+
success(run(cmd))
315+
end
316+
close(f)
317+
end
318+
309319
end

stdlib/Logging/test/threads_exec.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Logging
2+
3+
function test_threads_exec(n)
4+
Threads.@threads for i in 1:n
5+
x = rand()
6+
@debug "iteration" i x Threads.threadid()
7+
@info "iteration" i x Threads.threadid()
8+
@warn "iteration" i x Threads.threadid()
9+
@error "iteration" i x Threads.threadid()
10+
end
11+
end
12+
13+
test_threads_exec(100000)

0 commit comments

Comments
 (0)