internal/test/integration/workspace: fix TestUseGoWork

Fix a tricky race in TestUseGoWork, where a view recalculation causes
diagnostics in modb/go.mod to be cleared.

Prior to CL 675016, we'd expect a diagnostic in modb/go.mod because it
had an open file, and so zero config would cause it to be diagnosed.
Subsequent to CL 675016, there is no file, so the diagnostic should be
cleared, but because we *weren't* guarding the assertion in an
'AfterChange' (for obsolete historical reasons, I think), the 'Await'
expression was immediately satisfied except in the rare cases when the
rediagnosis won the race. This is one of the reasons why an unguarded
'Await' is almost always problematic, not least because its failure mode
is to just hang.

Invert the sense of the assertion, and guard the problematic await (and
others) in this test.

Fixes golang/go#74165

Change-Id: Ie5b9ab6b87ded41afe68830136196ef3588422a7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/684656
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
diff --git a/gopls/internal/test/integration/workspace/workspace_test.go b/gopls/internal/test/integration/workspace/workspace_test.go
index a00db44..2d3eaeb 100644
--- a/gopls/internal/test/integration/workspace/workspace_test.go
+++ b/gopls/internal/test/integration/workspace/workspace_test.go
@@ -645,7 +645,7 @@
 		//
 		// TODO: should editing the go.work above cause modb diagnostics to be
 		// suppressed?
-		env.Await(env.DoneWithChange())
+		env.AfterChange()
 		if err := checkHelloLocation("modb/b/b.go"); err != nil {
 			t.Fatal(err)
 		}
@@ -656,12 +656,9 @@
 			t.Fatal(err)
 		}
 
-		// This fails if guarded with a OnceMet(DoneWithSave(), ...), because it is
-		// delayed (and therefore not synchronous with the change).
-		//
-		// Note: this check used to assert on NoDiagnostics, but with zero-config
-		// gopls we still have diagnostics.
-		env.Await(Diagnostics(ForFile("modb/go.mod"), WithMessage("example.com is not used")))
+		// Since no file in modb is open, there should be no view containing
+		// modb/go.mod, and we should clear its diagnostics.
+		env.AfterChange(NoDiagnostics(ForFile("modb/go.mod")))
 
 		// Test Formatting.
 		env.SetBufferContent("go.work", `go 1.18
@@ -673,7 +670,7 @@
 )
 `) // TODO(matloob): For some reason there's a "start position 7:0 is out of bounds" error when the ")" is on the last character/line in the file. Rob probably knows what's going on.
 		env.SaveBuffer("go.work")
-		env.Await(env.DoneWithSave())
+		env.AfterChange()
 		gotWorkContents := env.ReadWorkspaceFile("go.work")
 		wantWorkContents := `go 1.18