Skip to content

Commit f4fcd7a

Browse files
committed
test/integration/goDebug: make invalid flag test faster
This test is to check if the debugging session fails somehow if an invalid dlv flag is passed. Previously, this test relied on the timeout of dap server start. (See spawnDlvDapServerProcess and its use of 30_000msec timeout) That was why this test always took 30sec to complete. This CL changes the test to wait for the output message that includes the usage error information, instead of waiting for the timeout. I think we can also improve spawnDlvDapServerProcess to fail sooner when dlv server start up failure is observed instead of relaying on the timeout. However, the start up logic is complex enough. I am reluctant to add more complexity to optimize for this less common failure case. Change-Id: I16069dc1c6879ce137b7799366e36e429500ea53 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/418899 TryBot-Result: kokoro <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
1 parent cbecbf8 commit f4fcd7a

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

test/integration/goDebug.test.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,24 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean, withConsole?: string) =>
510510
await assertStoppedLocation;
511511
}
512512

513+
/**
514+
* Helper function to create a promise that's resolved when
515+
* output event with any of the provided strings is observed.
516+
*/
517+
async function waitForOutputMessage(dc: DebugClient, ...patterns: string[]): Promise<DebugProtocol.Event> {
518+
return await new Promise<DebugProtocol.Event>((resolve, reject) => {
519+
dc.on('output', (event) => {
520+
for (const pattern of patterns) {
521+
if (event.body.output.includes(pattern)) {
522+
// Resolve when we have found the event that we want.
523+
resolve(event);
524+
return;
525+
}
526+
}
527+
});
528+
});
529+
}
530+
513531
/**
514532
* Helper function to assert that a variable has a particular value.
515533
* This should be called when the program is stopped.
@@ -775,7 +793,6 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean, withConsole?: string) =>
775793
this.skip(); // not working in dlv-dap.
776794
}
777795

778-
// TODO(hyangah): why does it take 30sec?
779796
const PROGRAM = path.join(DATA_ROOT, 'baseTest');
780797
const config = {
781798
name: 'Launch',
@@ -785,13 +802,16 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean, withConsole?: string) =>
785802
program: PROGRAM,
786803
dlvFlags: ['--invalid']
787804
};
788-
try {
789-
await initializeDebugConfig(config);
790-
await dc.initializeRequest();
791-
} catch (err) {
792-
return;
793-
}
794-
throw new Error('does not report error on invalid delve flag');
805+
806+
await initializeDebugConfig(config);
807+
808+
await Promise.race([
809+
// send an initialize request, which triggers launchDelveDAP
810+
// from the thin adapter. We expect no response.
811+
dc.initializeRequest().then(() => Promise.reject('unexpected initialization success')),
812+
// we expect the useful error message.
813+
waitForOutputMessage(dc, 'Error: unknown flag: --invalid')
814+
]);
795815
});
796816

797817
test('should run program with showLog=false and logOutput specified', async () => {
@@ -951,15 +971,7 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean, withConsole?: string) =>
951971
});
952972

953973
async function waitForHelloGoodbyeOutput(dc: DebugClient): Promise<DebugProtocol.Event> {
954-
return await new Promise<DebugProtocol.Event>((resolve, reject) => {
955-
dc.on('output', (event) => {
956-
if (event.body.output === 'Hello, World!\n' || event.body.output === 'Goodbye, World.\n') {
957-
// Resolve when we have found the event that we want.
958-
resolve(event);
959-
return;
960-
}
961-
});
962-
});
974+
return waitForOutputMessage(dc, 'Hello, World!\n', 'Goodbye, World.\n');
963975
}
964976

965977
test('should run program with cwd set (noDebug)', async () => {

0 commit comments

Comments
 (0)