Stop linking testify into production binaries via testsignal - #1342
Merged
Conversation
added 2 commits
August 4, 2026 23:15
`testsignal` is production code — its own doc comment says it's designed
to have "minimal impact on the production code that calls into it" — but
it imported `riversharedtest` for a single function, `WaitTimeout`.
Go initializes every imported package, so nothing in that graph can be
eliminated by the linker. The result is that testify, go-spew, goleak,
and yaml end up in every binary that uses River. Measured with
`go tool nm -size` on a minimal program importing `river` and
`riverdriver/riverpgxv5`:
github.com/stretchr/testify 18 symbols / 1168 bytes
github.com/davecgh/go-spew 11 symbols / 1312 bytes
go.uber.org/goleak 8 symbols / 896 bytes
gopkg.in/yaml 22 symbols / 4320 bytes
riversharedtest 13 symbols / 2248 bytes
`WaitTimeout` depends only on `os` and `time`, so move it to
`rivershared/util/testutil`, which `testsignal` already imports and which
has no dependencies outside the standard library. `riversharedtest.WaitTimeout`
stays as a wrapper so no public API changes, and its two internal callers,
`WaitOrTimeout` and `WaitOrTimeoutN`, are untouched. Its test moves
alongside the implementation.
After the move, the same program links no testify, go-spew, goleak, yaml,
or riversharedtest symbols at all: 951 fewer symbols and 957 KB less
binary.
Contributor
|
@e-yavuz-1 Dang great find. Do you think could sign our CLA? https://github.com/riverqueue/rivercla Otherwise, LGTM. |
Contributor
|
Also adding #1343 for a more structural fix by checking for this problem during linting. |
Contributor
Author
|
@brandur CLA signed. |
brandur
approved these changes
Aug 5, 2026
brandur
added a commit
that referenced
this pull request
Aug 6, 2026
This one's aimed at producing a more permanent structural fix for #1342 by keeping an eye out for the same problematic condition using the depguard lint. As a summary of the problem corrected by #1342: * We use the `testsignal` package in all kinds of non-test code, so packages including River always build against it. * `testsignal` was importing `riversharedtest`, which imports Testify, Goleak, YAML (through Testify). * This was causing all packages built against River to pick up an extra ~10 kB worth of dependencies in their production builds, which is bad. Here, add some new rules for depguard: * Don't allow `testsignal` to have any dependencies beyond stdlib and `testutil`. * Don't allow `testutil` to have any non-stdlib dependencies. This rule is so that `testsignal` doesn't pick up unexpected dependencies transitively through `testutil`.
brandur
added a commit
that referenced
this pull request
Aug 6, 2026
This one's aimed at producing a more permanent structural fix for #1342 by keeping an eye out for the same problematic condition using the depguard lint. As a summary of the problem corrected by #1342: * We use the `testsignal` package in all kinds of non-test code, so packages including River always build against it. * `testsignal` was importing `riversharedtest`, which imports Testify, Goleak, YAML (through Testify). * This was causing all packages built against River to pick up an extra ~10 kB worth of dependencies in their production builds, which is bad. Here, add some new rules for depguard: * Don't allow test packages like Goleak or Testify to be imported by any non-test Go files. We make an exception for internal test support packages like `riverdbtest` and `riverdrivertest`. * Don't allow `testsignal` to have any dependencies beyond stdlib and `testutil`. * Don't allow `testutil` to have any non-stdlib dependencies. This rule is so that `testsignal` doesn't pick up unexpected dependencies transitively through `testutil`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
testsignalis production code — its own doc comment says it's designed to have "minimal impact on the production code that calls into it" — but it importedriversharedtestfor a single function,WaitTimeout.Go initializes every imported package, so nothing in that graph can be eliminated by the linker. The result is that testify, go-spew, goleak, and yaml end up in every binary that uses River. Measured with
go tool nm -sizeon a minimal program importingriverandriverdriver/riverpgxv5:WaitTimeoutdepends only onosandtime, so move it torivershared/util/testutil, whichtestsignalalready imports and which has no dependencies outside the standard library.riversharedtest.WaitTimeoutstays as a wrapper so no public API changes, and its two internal callers,WaitOrTimeoutandWaitOrTimeoutN, are untouched. Its test moves alongside the implementation.After the move, the same program links no testify, go-spew, goleak, yaml, or riversharedtest symbols at all: 951 fewer symbols and 957 KB less binary.