Skip to content

Stop linking testify into production binaries via testsignal - #1342

Open
e-yavuz-1 wants to merge 2 commits into
riverqueue:masterfrom
e-yavuz-1:fix/testsignal-no-testify
Open

Stop linking testify into production binaries via testsignal#1342
e-yavuz-1 wants to merge 2 commits into
riverqueue:masterfrom
e-yavuz-1:fix/testsignal-no-testify

Conversation

@e-yavuz-1

Copy link
Copy Markdown

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.

Yavuz 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.
@brandur

brandur commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@e-yavuz-1 Dang great find. Do you think could sign our CLA? https://github.com/riverqueue/rivercla

Otherwise, LGTM.

@brandur

brandur commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Also adding #1343 for a more structural fix by checking for this problem during linting.

@e-yavuz-1

e-yavuz-1 commented Aug 5, 2026

Copy link
Copy Markdown
Author

@brandur CLA signed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants