-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/regtest: simplify awaiting diagnostics from a change
When awaiting diagnostics, we should almost always wrap expectations in a OnceMet(precondition, ...), so that tests do not hang indefinitely if the diagnostic pass completes and the expectations are still not met. Before this change, the user must be careful to pass in the correct precondition (or combination of preconditions), else they may be susceptible to races. This change adds an AllOf combinator, and uses it to define a new DoneDiagnosingChanges expectation that waits for all anticipated diagnostic passes to complete. This should fix the race in TestUnknownRevision. We should apply a similar transformation throughout the regression test suites. To make this easier, add a shorter AfterChange helper that implements the common pattern. Fixes golang/go#55070 Change-Id: Ie0e3c4701fba7b1d10de6b43d776562d198ffac9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/448115 Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
Showing
3 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -633,7 +633,7 @@ func main() { | |
|
||
d := protocol.PublishDiagnosticsParams{} | ||
env.Await( | ||
OnceMet( | ||
env.AfterChange( | ||
// Make sure the diagnostic mentions the new version -- the old diagnostic is in the same place. | ||
env.DiagnosticAtRegexpWithMessage("a/go.mod", "example.com v1.2.3", "[email protected]"), | ||
ReadDiagnostics("a/go.mod", &d), | ||
|
@@ -646,8 +646,10 @@ func main() { | |
env.ApplyCodeAction(qfs[0]) // Arbitrarily pick a single fix to apply. Applying all of them seems to cause trouble in this particular test. | ||
env.SaveBuffer("a/go.mod") // Save to trigger diagnostics. | ||
env.Await( | ||
EmptyDiagnostics("a/go.mod"), | ||
env.DiagnosticAtRegexp("a/main.go", "x = "), | ||
env.AfterChange( | ||
EmptyDiagnostics("a/go.mod"), | ||
env.DiagnosticAtRegexp("a/main.go", "x = "), | ||
), | ||
) | ||
}) | ||
}) | ||
|
@@ -677,17 +679,23 @@ func main() { | |
runner.Run(t, known, func(t *testing.T, env *Env) { | ||
env.OpenFile("a/go.mod") | ||
env.Await( | ||
env.DiagnosticAtRegexp("a/main.go", "x = "), | ||
env.AfterChange( | ||
env.DiagnosticAtRegexp("a/main.go", "x = "), | ||
), | ||
) | ||
env.RegexpReplace("a/go.mod", "v1.2.3", "v1.2.2") | ||
env.Editor.SaveBuffer(env.Ctx, "a/go.mod") // go.mod changes must be on disk | ||
env.Await( | ||
env.DiagnosticAtRegexp("a/go.mod", "example.com v1.2.2"), | ||
env.AfterChange( | ||
env.DiagnosticAtRegexp("a/go.mod", "example.com v1.2.2"), | ||
), | ||
) | ||
env.RegexpReplace("a/go.mod", "v1.2.2", "v1.2.3") | ||
env.Editor.SaveBuffer(env.Ctx, "a/go.mod") // go.mod changes must be on disk | ||
env.Await( | ||
env.DiagnosticAtRegexp("a/main.go", "x = "), | ||
env.AfterChange( | ||
env.DiagnosticAtRegexp("a/main.go", "x = "), | ||
), | ||
) | ||
}) | ||
}) | ||
|