Skip to content

Commit 2e5fc54

Browse files
committed
gopls/internal/regtest/codelens: avoid a race in TestUpgradeCodelens
Avoid (but do not fix) a race in TestUpgradeCodelens: because upgrade and vuln diagnostics access state on the View, they race with asynchronous diagnostics, which assume that diagnostics are idempotent. Diagnostics _should_ be idempotent: we should create a new snapshot when the view state changes (and inject that state into the snapshot). But that is a larger change, and this CL will confirm the hypothesis above if the flakes go away. For golang/go#58750 Change-Id: If827aab0ae187c5c377d830d76caf626b51bc3bc Reviewed-on: https://go-review.googlesource.com/c/tools/+/521895 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 6eca6df commit 2e5fc54

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

gopls/internal/regtest/codelens/codelens_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,25 @@ require golang.org/x/hello v1.2.3
199199
}
200200
for _, vendoring := range []bool{false, true} {
201201
t.Run(fmt.Sprintf("Upgrade individual dependency vendoring=%v", vendoring), func(t *testing.T) {
202-
WithOptions(ProxyFiles(proxyWithLatest)).Run(t, shouldUpdateDep, func(t *testing.T, env *Env) {
202+
WithOptions(
203+
ProxyFiles(proxyWithLatest),
204+
).Run(t, shouldUpdateDep, func(t *testing.T, env *Env) {
203205
if vendoring {
204206
env.RunGoCommandInDirWithEnv("a", []string{"GOWORK=off"}, "mod", "vendor")
205207
}
206208
env.AfterChange()
207209
env.OpenFile("a/go.mod")
208210
env.OpenFile("b/go.mod")
211+
212+
// Await the diagnostics resulting from opening the modfiles, because
213+
// otherwise they may cause races when running asynchronously to the
214+
// explicit re-diagnosing below.
215+
//
216+
// TODO(golang/go#58750): there is still a race here, inherent to
217+
// accessing state on the View; we should create a new snapshot when
218+
// the view diagnostics change.
219+
env.AfterChange()
220+
209221
env.ExecuteCodeLensCommand("a/go.mod", command.CheckUpgrades, nil)
210222
d := &protocol.PublishDiagnosticsParams{}
211223
env.OnceMet(

0 commit comments

Comments
 (0)