Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testr: prevent panic when test keeps goroutines running #168

Closed
wants to merge 1 commit into from

Commits on Dec 8, 2022

  1. testr: prevent panic when test keeps goroutines running

    When a test completes, the testing.T becomes unusable. If a test hasn't
    properly stopped goroutines, those might continue to use the testr instance for
    logging. It's better to silently discard the log output than to panic.
    
    Without the testr.go changes, this new test triggers that panic:
    
    === RUN   TestStop
    --- PASS: TestStop (0.00s)
    PASS
    panic: Log in goroutine after TestStop has completed: "level"=0 "msg"="simple info message"
    
    $ go test -run=TestStop -v .
    goroutine 7 [running]:
    testing.(*common).logDepth(0xc000007860, {0xc00011e060, 0x26}, 0x3)
    	/nvme/gopath/go-1.19/src/testing/testing.go:894 +0x4c7
    testing.(*common).log(...)
    	/nvme/gopath/go-1.19/src/testing/testing.go:876
    testing.(*common).Log(0xc000007860, {0xc00011a010?, 0x4bb194?, 0x0?})
    	/nvme/gopath/go-1.19/src/testing/testing.go:917 +0x4e
    github.com/go-logr/logr/testr.logInfo({0x561d88, 0xc000007860}, 0x420e27?, 0x400000?, {0x53544b?, 0xc000086d38?}, {0x0?, 0x64d480?, 0x40c75e?})
    	/nvme/gopath/src/github.com/go-logr/logr/testr/testr.go:101 +0x11d
    github.com/go-logr/logr/testr.testloggerInterface.Info({{0x0, {0x560eb8, 0x0}, {0x0, 0x0, 0x0}, {0x0, 0x0}, 0x1, 0xc0000ae190}, ...}, ...)
    	/nvme/gopath/src/github.com/go-logr/logr/testr/testr.go:148 +0x106
    github.com/go-logr/logr.Logger.Info({{0x5621c8?, 0xc000014300?}, 0x0?}, {0x53544b, 0x13}, {0x0, 0x0, 0x0})
    	/nvme/gopath/src/github.com/go-logr/logr/logr.go:278 +0xe4
    github.com/go-logr/logr/testr.TestStop.func1()
    	/nvme/gopath/src/github.com/go-logr/logr/testr/testr_test.go:124 +0xd4
    created by github.com/go-logr/logr/testr.TestStop
    	/nvme/gopath/src/github.com/go-logr/logr/testr/testr_test.go:116 +0xd8
    FAIL	github.com/go-logr/logr/testr	0.006s
    FAIL
    pohly committed Dec 8, 2022
    Configuration menu
    Copy the full SHA
    5ba6474 View commit details
    Browse the repository at this point in the history