File tree Expand file tree Collapse file tree 2 files changed +39
-7
lines changed Expand file tree Collapse file tree 2 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -306,14 +306,45 @@ end
306
306
@test isempty (undoc)
307
307
end
308
308
309
- @testset " thread safety" begin
310
- cmd = ` $(Base. julia_cmd ()) -t4 $(joinpath (@__DIR__ , " threads_exec.jl" )) `
309
+ @testset " Logging when multithreaded" begin
310
+ n = 10000
311
+ cmd = ` $(Base. julia_cmd ()) -t4 --color=no $(joinpath (@__DIR__ , " threads_exec.jl" )) $n `
311
312
fname = tempname ()
312
- f = open (fname, " w" )
313
- redirect_stderr (f) do
314
- success (run (cmd))
313
+ @testset " Thread safety" begin
314
+ f = open (fname, " w" )
315
+ @test success (run (pipeline (cmd, stderr = f)))
316
+ close (f)
317
+ end
318
+
319
+ @testset " No tearing in log printing" begin
320
+ # Check for print tearing by verifying that each log entry starts and ends correctly
321
+ f = open (fname, " r" )
322
+ entry_start = r" ^┌ (Info|Warning|Error): iteration"
323
+ entry_end = r" ^└ "
324
+
325
+ open_entries = 0
326
+ total_entries = 0
327
+ for line in eachline (fname)
328
+ starts = count (entry_start, line)
329
+ starts > 1 && error (" Interleaved logs: Multiple log entries started on one line" )
330
+ if starts == 1
331
+ open_entries += 1
332
+ total_entries += 1
333
+ end
334
+
335
+ ends = count (entry_end, line)
336
+ starts == 1 && ends == 1 && error (" Interleaved logs: Log entry started and and another ended on one line" )
337
+ ends > 1 && error (" Interleaved logs: Multiple log entries ended on one line" )
338
+ if ends == 1
339
+ open_entries -= 1
340
+ end
341
+
342
+ @test open_entries >= 0 # Ensure no mismatched log entries
343
+ end
344
+
345
+ @test open_entries == 0 # Ensure all entries closed properly
346
+ @test total_entries == n * 3 # Ensure all logs were printed (3 because @debug is hidden)
315
347
end
316
- close (f)
317
348
end
318
349
319
350
end
Original file line number Diff line number Diff line change @@ -10,4 +10,5 @@ function test_threads_exec(n)
10
10
end
11
11
end
12
12
13
- test_threads_exec (100000 )
13
+ n = parse (Int, ARGS [1 ])
14
+ test_threads_exec (n)
You can’t perform that action at this time.
0 commit comments