11module ParallelTestRunner
22
33export runtests, addworkers, addworker
4+ public extract_flag!
45
56using Distributed
67using Dates
@@ -100,7 +101,7 @@ struct TestIOContext
100101 rss_align:: Int
101102end
102103
103- function test_IOContext (:: Type{TestRecord } , stdout :: IO , stderr :: IO , lock:: ReentrantLock , name_align:: Int )
104+ function test_IOContext (:: Type{<:AbstractTestRecord } , stdout :: IO , stderr :: IO , lock:: ReentrantLock , name_align:: Int )
104105 elapsed_align = textwidth (" Time (s)" )
105106 gc_align = textwidth (" GC (s)" )
106107 percent_align = textwidth (" GC %" )
@@ -115,7 +116,7 @@ function test_IOContext(::Type{TestRecord}, stdout::IO, stderr::IO, lock::Reentr
115116 )
116117end
117118
118- function print_header (:: Type{TestRecord } , ctx:: TestIOContext , testgroupheader, workerheader)
119+ function print_header (:: Type{<:AbstractTestRecord } , ctx:: TestIOContext , testgroupheader, workerheader)
119120 lock (ctx. lock)
120121 try
121122 printstyled (ctx. stdout , " " ^ (ctx. name_align + textwidth (testgroupheader) - 3 ), " │ " )
@@ -129,7 +130,7 @@ function print_header(::Type{TestRecord}, ctx::TestIOContext, testgroupheader, w
129130 end
130131end
131132
132- function print_test_started (:: Type{TestRecord } , wrkr, test, ctx:: TestIOContext )
133+ function print_test_started (:: Type{<:AbstractTestRecord } , wrkr, test, ctx:: TestIOContext )
133134 lock (ctx. lock)
134135 try
135136 printstyled (ctx. stdout , test, lpad (" ($wrkr )" , ctx. name_align - textwidth (test) + 1 , " " ), " │" , color = :white )
@@ -143,7 +144,7 @@ function print_test_started(::Type{TestRecord}, wrkr, test, ctx::TestIOContext)
143144 end
144145end
145146
146- function print_test_finished (record:: TestRecord , wrkr, test, ctx:: TestIOContext )
147+ function print_test_finished (record:: AbstractTestRecord , wrkr, test, ctx:: TestIOContext )
147148 lock (ctx. lock)
148149 try
149150 printstyled (ctx. stdout , test, color = :white )
@@ -158,7 +159,7 @@ function print_test_finished(record::TestRecord, wrkr, test, ctx::TestIOContext)
158159 alloc_str = @sprintf (" %5.2f" , record. bytes / 2 ^ 20 )
159160 printstyled (ctx. stdout , lpad (alloc_str, ctx. alloc_align, " " ), " │ " , color = :white )
160161
161- rss_str = @sprintf (" %5.2f" , record. rss / 2 ^ 20 )
162+ rss_str = @sprintf (" %5.2f" , memory_usage ( record) / 2 ^ 20 )
162163 printstyled (ctx. stdout , lpad (rss_str, ctx. rss_align, " " ), " │\n " , color = :white )
163164
164165 flush (ctx. stdout )
@@ -167,7 +168,7 @@ function print_test_finished(record::TestRecord, wrkr, test, ctx::TestIOContext)
167168 end
168169end
169170
170- function print_test_failed (record:: TestRecord , wrkr, test, ctx:: TestIOContext )
171+ function print_test_failed (record:: AbstractTestRecord , wrkr, test, ctx:: TestIOContext )
171172 lock (ctx. lock)
172173 try
173174 printstyled (ctx. stderr , test, color = :red )
@@ -193,7 +194,7 @@ function print_test_failed(record::TestRecord, wrkr, test, ctx::TestIOContext)
193194 end
194195end
195196
196- function print_test_crashed (:: Type{TestRecord } , wrkr, test, ctx:: TestIOContext )
197+ function print_test_crashed (:: Type{<:AbstractTestRecord } , wrkr, test, ctx:: TestIOContext )
197198 lock (ctx. lock)
198199 try
199200 printstyled (ctx. stderr , test, color = :red )
212213
213214#
214215# entry point
215- #
216+ #
216217
217- function runtest (:: Type{TestRecord} , f, name, init_code, color)
218+ function runtest (:: Type{TestRecord} , f, name, init_code, color, custom_args )
218219 function inner ()
219220 # generate a temporary module to execute the tests in
220221 mod = @eval (Main, module $ (gensym (name)) end )
@@ -466,7 +467,8 @@ Workers are automatically recycled when they exceed memory limits to prevent out
466467issues during long test runs. The memory limit is set based on system architecture.
467468"""
468469function runtests (mod:: Module , ARGS ; test_filter = Returns (true ), RecordType = TestRecord,
469- custom_tests:: Dict{String, Expr} = Dict {String, Expr} (), init_code = :(),
470+ custom_tests:: Dict{String, Expr} = Dict {String, Expr} (), init_code = :(),
471+ custom_record_init = :(), custom_args = (;),
470472 test_worker = Returns (nothing ), stdout = Base. stdout , stderr = Base. stderr )
471473 #
472474 # set-up
@@ -789,8 +791,9 @@ function runtests(mod::Module, ARGS; test_filter = Returns(true), RecordType = T
789791 put! (printer_channel, (:started , test, wrkr))
790792 result = try
791793 Distributed. remotecall_eval (Main, wrkr, :(import ParallelTestRunner))
794+ custom_record_init != :() && Distributed. remotecall_eval (Main, wrkr, custom_record_init)
792795 remotecall_fetch (runtest, wrkr, RecordType, test_runners[test], test,
793- init_code, io_ctx. color)
796+ init_code, io_ctx. color, custom_args )
794797 catch ex
795798 if isa (ex, InterruptException)
796799 # the worker got interrupted, signal other tasks to stop
0 commit comments