Skip to content

Commit fa1bd8a

Browse files
committed
extension/test/integration: fix timeout flakiness caused by the dlv command
The flakiness is caused by dlv substitute-path-guess-helper failed to return within 2 seconds. Using beforeEach and afterEach to create sandboxes and cleanup. Instead of executing the dlv command, mock the guess function to make it reliable. Change-Id: Ib73aadc2d04d3d2f0c692def1565715869c6e9cf Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/694096 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent ea1c220 commit fa1bd8a

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

extension/src/goDebugConfiguration.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,9 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
387387
/**
388388
* Calls `dlv substitute-path-guess-helper` to get a set of parameters used by Delve to guess the substitutePath configuration after also examining the executable.
389389
*
390-
* Exported for testing.
391-
*
392390
* See https://github.com/go-delve/delve/blob/d5fb3bee427202f0d4b1683bf743bfd2adb41757/service/debugger/debugger.go#L2466
393391
*/
394-
public async guessSubstitutePath(): Promise<object | null> {
392+
async guessSubstitutePath(): Promise<object | null> {
395393
return new Promise((resolve) => {
396394
const child = spawn(getBinPath('dlv'), ['substitute-path-guess-helper']);
397395
let stdoutData = '';

extension/test/integration/goDebugConfiguration.test.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,16 @@ suite('Debug Configuration Auto Mode', () => {
965965

966966
suite('Debug Configuration Default DebugAdapter', () => {
967967
const debugConfigProvider = new GoDebugConfigurationProvider();
968+
let sandbox: sinon.SinonSandbox;
969+
970+
setup(() => {
971+
sandbox = sinon.createSandbox();
972+
});
973+
974+
teardown(() => {
975+
sandbox.restore();
976+
});
977+
968978
test("default debugAdapter should be 'dlv-dap'", async () => {
969979
const config = {
970980
name: 'Launch',
@@ -979,7 +989,7 @@ suite('Debug Configuration Default DebugAdapter', () => {
979989
assert.strictEqual(resolvedConfig['debugAdapter'], 'dlv-dap');
980990
});
981991

982-
test('default debugAdapter for remote mode should be determined by `dlv substitute-path-guess-helper`', async () => {
992+
test('remote mode: sets adapter based on the extension preview status when dlv path guessing fails', async () => {
983993
const config = {
984994
name: 'Attach',
985995
type: 'go',
@@ -989,15 +999,33 @@ suite('Debug Configuration Default DebugAdapter', () => {
989999
cwd: '/path'
9901000
};
9911001

1002+
const guessStub = sandbox.stub(debugConfigProvider, 'guessSubstitutePath').resolves(null);
1003+
9921004
await debugConfigProvider.resolveDebugConfiguration(undefined, config);
9931005
const resolvedConfig = config as any;
9941006

995-
const substitutePathGuess = await debugConfigProvider.guessSubstitutePath();
996-
let want = 'dlv-dap';
997-
if (substitutePathGuess === null) {
998-
want = 'legacy';
999-
}
1007+
const want = extensionInfo.isPreview ? 'dlv-dap' : 'legacy';
10001008
assert.strictEqual(resolvedConfig['debugAdapter'], want);
1009+
assert.ok(guessStub.calledOnce, 'guessSubstitutePath should have been called');
1010+
});
1011+
1012+
test('remote mode: sets debugAdapter to dlv-dap when dlv path guessing succeeds', async () => {
1013+
const config = {
1014+
name: 'Attach',
1015+
type: 'go',
1016+
request: 'attach',
1017+
mode: 'remote',
1018+
program: '/path/to/main_test.go',
1019+
cwd: '/path'
1020+
};
1021+
1022+
const guessStub = sandbox.stub(debugConfigProvider, 'guessSubstitutePath').resolves({});
1023+
1024+
await debugConfigProvider.resolveDebugConfiguration(undefined, config);
1025+
const resolvedConfig = config as any;
1026+
1027+
assert.strictEqual(resolvedConfig['debugAdapter'], 'dlv-dap');
1028+
assert.ok(guessStub.calledOnce, 'guessSubstitutePath should have been called');
10011029
});
10021030

10031031
test('debugAdapter=dlv-dap is allowed with remote mode', async () => {

0 commit comments

Comments
 (0)