Skip to content

Commit 9106148

Browse files
giordanovchuravy
andauthored
Add docstring for runtests (#2)
* Add docstring for `runtests` * Mention that tests `ARGS` can be changed with `Pkg.test(; test_args)` * `"$file.jl"` -> `file * ".jl"` Co-authored-by: Valentin Churavy <[email protected]> * Don't overstate the goodness of the load balancing Co-authored-by: Valentin Churavy <[email protected]> * Mention that partial matching is done with `startswith` * Make syntax of `--jobs=N` option clearer in info message --------- Co-authored-by: Valentin Churavy <[email protected]>
1 parent fe93cd7 commit 9106148

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

src/ParallelTestRunner.jl

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,59 @@ function runtest(::Type{TestRecord}, f, name)
200200
return res
201201
end
202202

203-
function runtests(ARGS, testfilter = _ -> true, RecordType = TestRecord)
203+
"""
204+
runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
205+
206+
Run Julia tests in parallel across multiple worker processes.
207+
208+
## Arguments
209+
210+
- `ARGS`: Command line arguments array, typically from `Base.ARGS`. When you run the tests with `Pkg.test`, this can be changed with the `test_args` keyword argument
211+
- `testfilter`: Optional function to filter which tests to run (default: run all tests)
212+
- `RecordType`: Type of test record to use for tracking test results (default: `TestRecord`)
213+
214+
## Command Line Options
215+
216+
- `--help`: Show usage information and exit
217+
- `--list`: List all available test files and exit
218+
- `--verbose`: Print more detailed information during test execution
219+
- `--quickfail`: Stop the entire test run as soon as any test fails
220+
- `--jobs=N`: Use N worker processes (default: based on CPU threads and available memory)
221+
- `TESTS...`: Filter tests by name, matched using `startswith`
222+
223+
## Behavior
224+
225+
- Automatically discovers all `.jl` files in the test directory (excluding `setup.jl` and `runtests.jl`)
226+
- Sorts tests by file size (largest first) for load balancing
227+
- Launches worker processes with appropriate Julia flags for testing
228+
- Monitors memory usage and recycles workers that exceed memory limits
229+
- Provides real-time progress output with timing and memory statistics
230+
- Handles interruptions gracefully (Ctrl+C)
231+
- Returns nothing, but throws `Test.FallbackTestSetException` if any tests fail
232+
233+
## Examples
234+
235+
```julia
236+
# Run all tests with default settings
237+
runtests(ARGS)
238+
239+
# Run only tests matching "integration"
240+
runtests(["integration"])
241+
242+
# Run with custom filter function
243+
runtests(ARGS, test -> occursin("unit", test))
244+
245+
# Use custom test record type
246+
runtests(ARGS, Returns(true), MyCustomTestRecord)
247+
```
248+
249+
## Memory Management
250+
251+
Workers are automatically recycled when they exceed memory limits to prevent
252+
out-of-memory issues during long test runs. The memory limit is set based on
253+
system architecture.
254+
"""
255+
function runtests(ARGS, testfilter = Returns(true), RecordType = TestRecord)
204256
do_help, _ = extract_flag!(ARGS, "--help")
205257
if do_help
206258
println(
@@ -260,10 +312,10 @@ function runtests(ARGS, testfilter = _ -> true, RecordType = TestRecord)
260312

261313
append!(tests, files)
262314
for file in files
263-
test_runners[file] = joinpath("$WORKDIR", "$file.jl")
315+
test_runners[file] = joinpath(WORKDIR, file * ".jl")
264316
end
265317
end
266-
sort!(tests; by = (file) -> stat(joinpath("$WORKDIR", "$file.jl")).size, rev = true)
318+
sort!(tests; by = (file) -> stat(joinpath(WORKDIR, file * ".jl")).size, rev = true)
267319
## finalize
268320
unique!(tests)
269321

@@ -292,7 +344,7 @@ function runtests(ARGS, testfilter = _ -> true, RecordType = TestRecord)
292344
memory_jobs = Int64(Sys.free_memory()) ÷ (2 * 2^30)
293345
jobs = max(1, min(jobs, memory_jobs))
294346
end
295-
@info "Running $jobs tests in parallel. If this is too many, specify the `--jobs` argument to the tests, or set the `JULIA_CPU_THREADS` environment variable."
347+
@info "Running $jobs tests in parallel. If this is too many, specify the `--jobs=N` argument to the tests, or set the `JULIA_CPU_THREADS` environment variable."
296348

297349
# add workers
298350
test_exeflags = Base.julia_cmd()

0 commit comments

Comments
 (0)