test/gopls: add time out in language client stop

Flush the trace if language server is still running after stop returns.

For golang/vscode-go#2454

Change-Id: I14b224e440d6208a31b3ed3cb16d68481254fc20
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/446297
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/test/gopls/extension.test.ts b/test/gopls/extension.test.ts
index 5cced68..972e8ad 100644
--- a/test/gopls/extension.test.ts
+++ b/test/gopls/extension.test.ts
@@ -116,11 +116,20 @@
 	}
 
 	public async teardown() {
-		await this.languageClient?.stop();
-		for (const d of this.disposables) {
-			d.dispose();
+		try {
+			await this.languageClient?.stop(1_000); // 1s timeout
+		} catch (e) {
+			console.log(`failed to stop gopls within 1sec: ${e}`);
+		} finally {
+			if (this.languageClient?.isRunning()) {
+				console.log(`failed to stop language client on time: ${this.languageClient?.state}`);
+				this.flushTrace(true);
+			}
+			for (const d of this.disposables) {
+				d.dispose();
+			}
+			this.languageClient = undefined;
 		}
-		this.languageClient = undefined;
 	}
 
 	public async openDoc(...paths: string[]) {