gopls/internal/test/integration: fix race
Gotta install the message collector before we trigger
the thing that causes the message to be sent!
Fixes golang/go#74072
Change-Id: Ia110703ff0a7ad6b32939be9cd6615cef649e6bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/680756
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
diff --git a/gopls/internal/test/integration/env.go b/gopls/internal/test/integration/env.go
index a2f5449..22680c6 100644
--- a/gopls/internal/test/integration/env.go
+++ b/gopls/internal/test/integration/env.go
@@ -202,6 +202,10 @@
// notifications. Call the resulting func to deregister the listener and
// receive all notifications that have occurred since the listener was
// registered.
+//
+// ListenToShownMessages should be called before the operation that
+// generates the showMessage event to ensure that the event is
+// reliably collected.
func (a *Awaiter) ListenToShownMessages() func() []*protocol.ShowMessageParams {
id := nextAwaiterRegistration.Add(1)
diff --git a/gopls/internal/test/integration/misc/generate_test.go b/gopls/internal/test/integration/misc/generate_test.go
index f5fe226..daa6599 100644
--- a/gopls/internal/test/integration/misc/generate_test.go
+++ b/gopls/internal/test/integration/misc/generate_test.go
@@ -119,8 +119,8 @@
`
Run(t, src, func(t *testing.T, env *Env) {
env.OpenFile("a/a.go")
- env.RegexpReplace("a/a.go", "var", "const")
collectMessages := env.Awaiter.ListenToShownMessages()
+ env.RegexpReplace("a/a.go", "var", "const")
env.Await(env.DoneWithChange())
messages := collectMessages()