Skip to content

x/tools/gopls/internal/test/integration: violates testing.T.FailNow precondition #72771

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

Open
adonovan opened this issue Mar 10, 2025 · 3 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

The documentation of testing.T says:

A test ends when its Test function returns or calls any of the methods FailNow, Fatal, Fatalf, SkipNow, Skip, or Skipf. Those methods, as well as the Parallel method, must be called only from the goroutine running the Test function.

However, this precondition is violated by gopls' integration test framework. The integration.Env captures the root testing.T, and uses it for many assertions (calls to t.Fatal) performed by the Env itself. But it is common for integration tests to create new subtests using t.Run and then call methods of Env that call Env.T.Fatal.

I don't know whether this is a real problem--perhaps the testing package must already be robust to this kind of misuse--but it does result in the testing package emitting messages like this one:

testing.go:1682: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test

(source: https://logs.chromium.org/logs/golang/buildbucket/cr-buildbucket/8720772441964325377/+/u/step/22/log/2)

I wonder whether this is something we need to be more careful about.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Mar 10, 2025
@gopherbot gopherbot added this to the Unreleased milestone Mar 10, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Mar 10, 2025
@findleyr
Copy link
Member

Hmm, indeed.

This is, of course, why you're not supposed to close over testing.T. I think it would be reasonable to revert this decision: yes all helpers would have to accept a T, but especially with most new tests being marker tests, that's probably fine.

@adonovan
Copy link
Member Author

all helpers would have to accept a T, but especially with most new tests being marker tests, that's probably fine.

I agree that would be a reasonable fix. I'm still not sure this is actually a problem in practice. (While studying the crash in the log above, I thought at first it might be relevant, but I'm not so sure now.)

@findleyr findleyr modified the milestones: Unreleased, gopls/backlog Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants