Commit cbbcc7c
Make TestLogger thread-safe (introduce a lock) (JuliaLang#54497)
Fixes JuliaLang#54439.
- Lock around concurrent accesses to .logs, .message_limits, and
.shouldlog_args.
- Copy the vector out of the logger at the end, to shield against
dangling Tasks.
Before:
```julia
julia> Threads.nthreads()
8
julia> function foo(n)
@info "Doing foo with n=$n"
@sync for i=1:n
Threads.@Spawn @info "Iteration $i"
end
42
end
foo (generic function with 1 method)
julia> for _ in 1:1000
@test_logs (:info,"Doing foo with n=10000") match_mode=:any foo(10_000)
end
julia+RAI(56155,0x1f5157ac0) malloc: double free for ptr 0x128248000
julia+RAI(56155,0x1f5157ac0) malloc: *** set a breakpoint in malloc_error_break to debug
[56155] signal (6): Abort trap: 6
in expression starting at REPL[8]:1
signal (6) thread (1) __pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 54370881 (Pool: 54363911; Big: 6970); GC: 119
[1] 56154 abort julia -tauto
```
After:
```julia
julia> Threads.nthreads()
8
julia> function foo(n)
@info "Doing foo with n=$n"
@sync for i=1:n
Threads.@Spawn @info "Iteration $i"
end
42
end
foo (generic function with 1 method)
julia> for _ in 1:1000
@test_logs (:info,"Doing foo with n=10000") match_mode=:any foo(10_000)
end
```
(no crash) :)1 parent 27438ec commit cbbcc7c
1 file changed
+28
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | | - | |
42 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| |||
80 | 85 | | |
81 | 86 | | |
82 | 87 | | |
83 | | - | |
| 88 | + | |
84 | 89 | | |
85 | 90 | | |
86 | 91 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
92 | 99 | | |
93 | 100 | | |
94 | 101 | | |
| |||
98 | 105 | | |
99 | 106 | | |
100 | 107 | | |
101 | | - | |
102 | | - | |
103 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
104 | 113 | | |
105 | 114 | | |
106 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
107 | 119 | | |
108 | 120 | | |
109 | 121 | | |
| |||
112 | 124 | | |
113 | 125 | | |
114 | 126 | | |
115 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
116 | 130 | | |
117 | 131 | | |
118 | 132 | | |
| |||
0 commit comments