From b5cbb50b2e508059f02b5f55ced925936c422d4f Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Thu, 4 Jun 2026 16:13:07 -0700 Subject: [PATCH 1/3] test: run unittests in parallel We have been using `go test -p=1` to avoid conflicts between unittests in different packages that both modify the database. However, this significantly slows down running tests. Since it's really on the the sa and ra packages that conflict, and some logic to just handle those. On my machine, this takes us from 56s to 20s (no race detection). When race detection is enabled, the difference is even more dramatic, because each package's test runner sleeps for a second before exiting. On my machine, 70s becomes 30s. --- test.sh | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/test.sh b/test.sh index b0001369009..736c84de680 100755 --- a/test.sh +++ b/test.sh @@ -82,7 +82,19 @@ function run_and_expect_silence() { # Testing Helpers # function run_unit_tests() { - go test "${UNIT_FLAGS[@]}" "${UNIT_PACKAGES[@]}" "${FILTER[@]}" + # If unit test packages are not specified: set flags to run unit tests + # for all boulder packages + if [ -z "${UNIT_PACKAGES[@]+x}" ] + then + # The ra and sa unittests conflict because they both mutate the database. + # Exclude the ra from our first test run, then run on its own. + # https://github.com/letsencrypt/boulder/issues/1499 + go test "${UNIT_FLAGS[@]}" $(go list ./... | grep -v boulder/ra) + go test ./ra + else + go test "${UNIT_FLAGS[@]}" "${UNIT_PACKAGES[@]}" "${FILTER[@]}" + fi + } # @@ -176,21 +188,6 @@ then FILTER=(--filter "${FILTER[@]}") fi -# If unit test packages are not specified: set flags to run unit tests -# for all boulder packages -if [ -z "${UNIT_PACKAGES[@]+x}" ] -then - # '-p=1' configures unit tests to run serially, rather than in parallel. Our - # unit tests depend on mutating a database and then cleaning up after - # themselves. If these test were run in parallel, they could fail spuriously - # due to one test modifying a table (especially registrations) while another - # test is reading from it. - # https://github.com/letsencrypt/boulder/issues/1499 - # https://pkg.go.dev/cmd/go#hdr-Testing_flags - UNIT_FLAGS+=("-p=1") - UNIT_PACKAGES+=("./...") -fi - print_heading "Boulder Test Suite CLI" print_heading "Settings:" From 84ca61edfc9706300e65c4d954ab4951dfa7e04e Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Thu, 4 Jun 2026 16:36:19 -0700 Subject: [PATCH 2/3] Use atexit_sleep_ms --- test.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test.sh b/test.sh index 736c84de680..b6d3f4590c8 100755 --- a/test.sh +++ b/test.sh @@ -82,6 +82,10 @@ function run_and_expect_silence() { # Testing Helpers # function run_unit_tests() { + # Sleep 50ms instead of 1000ms at the end of each package's unittests. + # Speeds up running lots of small unittests. + # https://go.dev/doc/articles/race_detector#Options + export atexit_sleep_ms=50 # If unit test packages are not specified: set flags to run unit tests # for all boulder packages if [ -z "${UNIT_PACKAGES[@]+x}" ] From a05b3e1dbd2b75249bf24da3b30320a3dac365bd Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Thu, 4 Jun 2026 16:45:17 -0700 Subject: [PATCH 3/3] set GORACE correctly --- test.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test.sh b/test.sh index b6d3f4590c8..e361eddc0e4 100755 --- a/test.sh +++ b/test.sh @@ -85,7 +85,7 @@ function run_unit_tests() { # Sleep 50ms instead of 1000ms at the end of each package's unittests. # Speeds up running lots of small unittests. # https://go.dev/doc/articles/race_detector#Options - export atexit_sleep_ms=50 + export GORACE="atexit_sleep_ms=50" # If unit test packages are not specified: set flags to run unit tests # for all boulder packages if [ -z "${UNIT_PACKAGES[@]+x}" ] @@ -93,14 +93,21 @@ function run_unit_tests() { # The ra and sa unittests conflict because they both mutate the database. # Exclude the ra from our first test run, then run on its own. # https://github.com/letsencrypt/boulder/issues/1499 - go test "${UNIT_FLAGS[@]}" $(go list ./... | grep -v boulder/ra) - go test ./ra + go_test $(go list ./... | grep -v boulder/ra) + go_test ./ra else - go test "${UNIT_FLAGS[@]}" "${UNIT_PACKAGES[@]}" "${FILTER[@]}" + go_test "${UNIT_PACKAGES[@]}" fi } +# +# Run `go test` on a given set of packages. +# +function go_test() { + go test "${UNIT_FLAGS[@]}" "${FILTER[@]}" "$@" +} + # # Main CLI Parser #