Skip to content

Commit

Permalink
Correctly pass parent session
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed May 8, 2019
1 parent 52fabbe commit d4b1a00
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export class ChildProcessAttachEventHandler implements IDebugSessionEventHandler
return;
}
const data = event.body! as ChildProcessLaunchData;
await this.childProcessAttachService.attach(data);
await this.childProcessAttachService.attach(data, event.session);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';

import { inject, injectable } from 'inversify';
import { DebugConfiguration, WorkspaceFolder } from 'vscode';
import { DebugConfiguration, DebugSession, WorkspaceFolder } from 'vscode';
import { IApplicationShell, IDebugService, IWorkspaceService } from '../../../common/application/types';
import { noop } from '../../../common/utils/misc';
import { captureTelemetry } from '../../../telemetry';
Expand All @@ -26,10 +26,10 @@ export class ChildProcessAttachService implements IChildProcessAttachService {
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService) { }

@captureTelemetry(EventName.DEBUGGER_ATTACH_TO_CHILD_PROCESS)
public async attach(data: ChildProcessLaunchData): Promise<void> {
public async attach(data: ChildProcessLaunchData, parentSession: DebugSession): Promise<void> {
const folder = this.getRelatedWorkspaceFolder(data);
const debugConfig = this.getAttachConfiguration(data);
const launched = await this.debugService.startDebugging(folder, debugConfig, this.debugService.activeDebugSession);
const launched = await this.debugService.startDebugging(folder, debugConfig, parentSession);
if (!launched) {
this.appShell.showErrorMessage(`Failed to launch debugger for child process ${data.processId}`).then(noop, noop);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/debugger/extension/hooks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ export type ChildProcessLaunchData = {

export const IChildProcessAttachService = Symbol('IChildProcessAttachService');
export interface IChildProcessAttachService {
attach(data: ChildProcessLaunchData): Promise<void>;
attach(data: ChildProcessLaunchData, parentSession: DebugSession): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ suite('Debug - Child Process', () => {
const attachService = mock(ChildProcessAttachService);
const handler = new ChildProcessAttachEventHandler(instance(attachService));
const body: any = {};
await handler.handleCustomEvent({ event: 'abc', body, session: {} as any });
verify(attachService.attach(body)).never();
const session: any = {};
await handler.handleCustomEvent({ event: 'abc', body, session });
verify(attachService.attach(body, session)).never();
});
test('Do not attach to child process if event is invalid', async () => {
const attachService = mock(ChildProcessAttachService);
const handler = new ChildProcessAttachEventHandler(instance(attachService));
const body: any = {};
await handler.handleCustomEvent({ event: PTVSDEvents.ChildProcessLaunched, body, session: {} as any });
verify(attachService.attach(body)).once();
const session: any = {};
await handler.handleCustomEvent({ event: PTVSDEvents.ChildProcessLaunched, body, session });
verify(attachService.attach(body, session)).once();
});
test('Exceptions are not bubbled up if data is invalid', async () => {
const attachService = mock(ChildProcessAttachService);
Expand All @@ -34,8 +36,9 @@ suite('Debug - Child Process', () => {
const attachService = mock(ChildProcessAttachService);
const handler = new ChildProcessAttachEventHandler(instance(attachService));
const body: any = {};
when(attachService.attach(body)).thenThrow(new Error('Kaboom'));
const session: any = {};
when(attachService.attach(body, session)).thenThrow(new Error('Kaboom'));
await handler.handleCustomEvent({ event: PTVSDEvents.ChildProcessLaunched, body, session: {} as any });
verify(attachService.attach(body)).once();
verify(attachService.attach(body, session)).once();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { expect } from 'chai';
import { anything, capture, instance, mock, verify, when } from 'ts-mockito';
import { DebugSession, Uri, WorkspaceFolder } from 'vscode';
import { Uri, WorkspaceFolder } from 'vscode';
import { ApplicationShell } from '../../../../client/common/application/applicationShell';
import { DebugService } from '../../../../client/common/application/debugService';
import { WorkspaceService } from '../../../../client/common/application/workspace';
Expand Down Expand Up @@ -38,11 +38,10 @@ suite('Debug - Attach to Child Process', () => {
command: 'request'
}
};
const parentDebugSession = { id: 'id' };
const session: any = {};
when(workspaceService.hasWorkspaceFolders).thenReturn(false);
when(debugService.activeDebugSession).thenReturn(parentDebugSession as DebugSession);
when(debugService.startDebugging(anything(), anything(), anything())).thenResolve(true as any);
await service.attach(data);
await service.attach(data, session);
verify(workspaceService.hasWorkspaceFolders).once();
verify(debugService.startDebugging(anything(), anything(), anything())).once();
});
Expand All @@ -69,12 +68,12 @@ suite('Debug - Attach to Child Process', () => {
}
};

const session: any = {};
when(workspaceService.hasWorkspaceFolders).thenReturn(false);
when(debugService.activeDebugSession).thenReturn(undefined);
when(debugService.startDebugging(anything(), anything(), anything())).thenResolve(false as any);
when(shell.showErrorMessage(anything())).thenResolve();

await service.attach(data);
await service.attach(data, session);

verify(workspaceService.hasWorkspaceFolders).once();
verify(debugService.startDebugging(anything(), anything(), anything())).once();
Expand Down Expand Up @@ -108,12 +107,12 @@ suite('Debug - Attach to Child Process', () => {
}
};

const session: any = {};
when(workspaceService.hasWorkspaceFolders).thenReturn(true);
when(workspaceService.workspaceFolders).thenReturn([wkspace1, rightWorkspaceFolder, wkspace2]);
when(debugService.activeDebugSession).thenReturn(undefined);
when(debugService.startDebugging(rightWorkspaceFolder, anything(), anything())).thenResolve(true as any);

await service.attach(data);
await service.attach(data, session);

verify(workspaceService.hasWorkspaceFolders).once();
verify(debugService.startDebugging(rightWorkspaceFolder, anything(), anything())).once();
Expand Down Expand Up @@ -147,12 +146,12 @@ suite('Debug - Attach to Child Process', () => {
}
};

const session: any = {};
when(workspaceService.hasWorkspaceFolders).thenReturn(true);
when(workspaceService.workspaceFolders).thenReturn([wkspace1, wkspace2]);
when(debugService.activeDebugSession).thenReturn(undefined);
when(debugService.startDebugging(undefined, anything(), anything())).thenResolve(true as any);

await service.attach(data);
await service.attach(data, session);

verify(workspaceService.hasWorkspaceFolders).once();
verify(debugService.startDebugging(undefined, anything(), anything())).once();
Expand Down Expand Up @@ -187,17 +186,18 @@ suite('Debug - Attach to Child Process', () => {
debugConfig.port = data.port;
debugConfig.name = `Child Process ${data.processId}`;
debugConfig.request = 'attach';
const session: any = {};

when(workspaceService.hasWorkspaceFolders).thenReturn(false);
when(debugService.activeDebugSession).thenReturn(undefined);
when(debugService.startDebugging(undefined, anything(), anything())).thenResolve(true as any);

await service.attach(data);
await service.attach(data, session);

verify(workspaceService.hasWorkspaceFolders).once();
verify(debugService.startDebugging(undefined, anything(), anything())).once();
const [, secondArg] = capture(debugService.startDebugging).last();
const [, secondArg, thirdArg] = capture(debugService.startDebugging).last();
expect(secondArg).to.deep.equal(debugConfig);
expect(thirdArg).to.deep.equal(session);
verify(shell.showErrorMessage(anything())).never();
});
test('Validate debug config when parent/root parent was attached', async () => {
Expand Down Expand Up @@ -230,18 +230,18 @@ suite('Debug - Attach to Child Process', () => {
debugConfig.port = data.port;
debugConfig.name = `Child Process ${data.processId}`;
debugConfig.request = 'attach';
const session: any = {};

when(workspaceService.hasWorkspaceFolders).thenReturn(false);
when(debugService.activeDebugSession).thenReturn(undefined);
when(debugService.startDebugging(undefined, anything(), anything())).thenResolve(true as any);
// when(debugService.startDebugging(undefined, debugConfig)).thenResolve(true as any);

await service.attach(data);
await service.attach(data, session);

verify(workspaceService.hasWorkspaceFolders).once();
verify(debugService.startDebugging(undefined, anything(), anything())).once();
const [, secondArg] = capture(debugService.startDebugging).last();
const [, secondArg, thirdArg] = capture(debugService.startDebugging).last();
expect(secondArg).to.deep.equal(debugConfig);
expect(thirdArg).to.deep.equal(session);
verify(shell.showErrorMessage(anything())).never();
});
});

0 comments on commit d4b1a00

Please sign in to comment.