test/integration/goDebug: verify goroutines running before switch

The test to make sure switch goroutines works by stepping between
two different goroutines. However, it was possible that when the
breakpoint in one goroutine was hit, the other had not started
running, so we were unable to get the threadID. This change sets
a breakpoint in each goroutine, to ensure that both are in the
appropriate functions before starting the tests.

Change-Id: I157a7d73a83722545db0878892e61079915043c8
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/313530
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/test/integration/goDebug.test.ts b/test/integration/goDebug.test.ts
index 374a3c5..ed14c7f 100644
--- a/test/integration/goDebug.test.ts
+++ b/test/integration/goDebug.test.ts
@@ -1567,7 +1567,8 @@
 		async function runSwitchGoroutineTest(stepFunction: string) {
 			const PROGRAM = path.join(DATA_ROOT, 'goroutineTest');
 			const FILE = path.join(PROGRAM, 'main.go');
-			const BREAKPOINT_LINE = 14;
+			const BREAKPOINT_LINE_MAIN_RUN1 = 6;
+			const BREAKPOINT_LINE_MAIN_RUN2 = 14;
 
 			const config = {
 				name: 'Launch',
@@ -1577,13 +1578,24 @@
 				program: PROGRAM
 			};
 			const debugConfig = await initializeDebugConfig(config);
-			await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE));
-			// Clear breakpoints to make sure they do not interrupt the stepping.
+			await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE_MAIN_RUN1));
+
+			// Set a breakpoint in run 2. 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({
+				source: { path: bp2.path },
+				breakpoints: [{ line: bp2.line }]
+			});
+			assert.ok(breakpointsResult.success);
+			await Promise.all([dc.continueRequest({ threadId: 1 }), dc.assertStoppedLocation('breakpoint', bp2)]);
+
+			// Clear breakpoints to make sure they do not interrupt the stepping.
+			const clearBreakpointsResult = await dc.setBreakpointsRequest({
 				source: { path: FILE },
 				breakpoints: []
 			});
-			assert.ok(breakpointsResult.success);
+			assert.ok(clearBreakpointsResult.success);
 
 			const threadsResponse = await dc.threadsRequest();
 			assert.ok(threadsResponse.success);