test/integration/goDebug: get goroutines reliably in switch goroutine test

switch goroutine test uses two goroutines. In order to get the goroutine
ids, the test called a threads request and searched 'main.run1' and 'main.run2'
from the goroutines' names. We observed there is no guarantee that the top
most stack contains the function names. It's possible that the goroutine is
running runtime code. For example, this is the threads response we got from
a failed test run in github action CI.

-> server: {"type":"request","seq":10,"command":"threads"}

<- server: {"seq":0,"type":"response","request_seq":10,"success":true,"command":"threads","body":{"threads":[
   {"id":1,"name":"[Go 1] main.main"},
   {"id":2,"name":"[Go 2] runtime.gopark"},
   {"id":3,"name":"[Go 3] runtime.gopark"},
   {"id":4,"name":"[Go 4] runtime.gopark"},
   {"id":17,"name":"[Go 17] runtime.sigtramp (Thread 13304)"},
   {"id":18,"name":"* [Go 18] main.run2 (Thread 13299)"}]}}

The goroutine 17 is running main.run1 but that is not the top most frame.
So, later when using the main.run1 goroutine's id, the test threw an error.

This change makes the test retrieve goroutine id when the breakpoint on
the goroutine is hit - so the main.run1 and main.run2 functions are in
the top of the stack.

Change-Id: I478d0d7e90730a710954d98c278fe2a7b4a7c3a1
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/314589
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/test/integration/goDebug.test.ts b/test/integration/goDebug.test.ts
index 637ea65..aae6587 100644
--- a/test/integration/goDebug.test.ts
+++ b/test/integration/goDebug.test.ts
@@ -1579,9 +1579,14 @@
 				program: PROGRAM
 			};
 			const debugConfig = await initializeDebugConfig(config);
+			// Set a breakpoint in run 1 and get the goroutine id.
 			await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE_MAIN_RUN1));
+			const threadsResponse1 = await dc.threadsRequest();
+			assert.ok(threadsResponse1.success);
+			const run1Goroutine = threadsResponse1.body.threads.find((val) => val.name.indexOf('main.run1') >= 0);
 
-			// Set a breakpoint in run 2. By setting breakpoints in both goroutine, we can make sure that both goroutines
+			// Set a breakpoint in run 2 and get the goroutine id.
+			// By setting breakpoints in both goroutine, we can make sure that both goroutines
 			// are running before continuing.
 			const bp2 = getBreakpointLocation(FILE, BREAKPOINT_LINE_MAIN_RUN2);
 			const breakpointsResult = await dc.setBreakpointsRequest({
@@ -1589,6 +1594,10 @@
 				breakpoints: [{ line: bp2.line }]
 			});
 			assert.ok(breakpointsResult.success);
+			const threadsResponse2 = await dc.threadsRequest();
+			assert.ok(threadsResponse2.success);
+			const run2Goroutine = threadsResponse2.body.threads.find((val) => val.name.indexOf('main.run2') >= 0);
+
 			await Promise.all([dc.continueRequest({ threadId: 1 }), dc.assertStoppedLocation('breakpoint', bp2)]);
 
 			// Clear breakpoints to make sure they do not interrupt the stepping.
@@ -1598,11 +1607,6 @@
 			});
 			assert.ok(clearBreakpointsResult.success);
 
-			const threadsResponse = await dc.threadsRequest();
-			assert.ok(threadsResponse.success);
-			const run1Goroutine = threadsResponse.body.threads.find((val) => val.name.indexOf('main.run1') >= 0);
-			const run2Goroutine = threadsResponse.body.threads.find((val) => val.name.indexOf('main.run2') >= 0);
-
 			// runStepFunction runs the necessary step function and resolves if it succeeded.
 			async function runStepFunction(
 				args: { threadId: number },