forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattach.test.ts
More file actions
124 lines (106 loc) · 4.84 KB
/
attach.test.ts
File metadata and controls
124 lines (106 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// tslint:disable:no-invalid-this max-func-body-length no-empty no-increment-decrement
import { expect } from 'chai';
import { ChildProcess } from 'child_process';
import * as getFreePort from 'get-port';
import * as path from 'path';
import { DebugClient } from 'vscode-debugadapter-testsupport';
import { createDeferred } from '../../client/common/helpers';
import { BufferDecoder } from '../../client/common/process/decoder';
import { ProcessService } from '../../client/common/process/proc';
import { AttachRequestArgumentsV1 } from '../../client/debugger/Common/Contracts';
import { PYTHON_PATH, sleep } from '../common';
import { initialize, IS_APPVEYOR, IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
import { DEBUGGER_TIMEOUT } from './common/constants';
const fileToDebug = path.join(__dirname, '..', '..', '..', 'src', 'testMultiRootWkspc', 'workspace5', 'remoteDebugger.py');
const ptvsdPath = path.join(__dirname, '..', '..', '..', 'pythonFiles', 'PythonTools');
const DEBUG_ADAPTER = path.join(__dirname, '..', '..', 'client', 'debugger', 'Main.js');
suite('Attach Debugger', () => {
let debugClient: DebugClient;
let procToKill: ChildProcess;
suiteSetup(initialize);
setup(async function () {
if (!IS_MULTI_ROOT_TEST || !TEST_DEBUGGER) {
this.skip();
}
await sleep(1000);
debugClient = new DebugClient('node', DEBUG_ADAPTER, 'python');
debugClient.defaultTimeout = DEBUGGER_TIMEOUT;
await debugClient.start();
});
teardown(async () => {
// Wait for a second before starting another test (sometimes, sockets take a while to get closed).
await sleep(1000);
try {
await debugClient.stop().catch(() => { });
} catch (ex) { }
if (procToKill) {
try {
procToKill.kill();
} catch { }
}
});
test('Confirm we are able to attach to a running program', async () => {
// Lets skip this test on AppVeyor (very flaky on AppVeyor).
if (IS_APPVEYOR) {
return;
}
const port = await getFreePort({ host: 'localhost', port: 3000 });
const args: AttachRequestArgumentsV1 = {
localRoot: path.dirname(fileToDebug),
remoteRoot: path.dirname(fileToDebug),
port: port,
host: 'localhost',
secret: 'super_secret'
};
const customEnv = { ...process.env };
// Set the path for PTVSD to be picked up.
// tslint:disable-next-line:no-string-literal
customEnv['PYTHONPATH'] = ptvsdPath;
const procService = new ProcessService(new BufferDecoder());
const result = procService.execObservable(PYTHON_PATH, [fileToDebug, port.toString()], { env: customEnv, cwd: path.dirname(fileToDebug) });
procToKill = result.proc;
const expectedOutputs = [
{ value: 'start', deferred: createDeferred() },
{ value: 'attached', deferred: createDeferred() },
{ value: 'end', deferred: createDeferred() }
];
const startOutputReceived = expectedOutputs[0].deferred.promise;
const attachedOutputReceived = expectedOutputs[1].deferred.promise;
const lastOutputReceived = expectedOutputs[2].deferred.promise;
result.out.subscribe(output => {
if (expectedOutputs[0].value === output.out) {
expectedOutputs.shift()!.deferred.resolve();
}
});
await startOutputReceived;
const initializePromise = debugClient.initializeRequest({
adapterID: 'python',
linesStartAt1: true,
columnsStartAt1: true,
supportsRunInTerminalRequest: true,
pathFormat: 'path'
});
await debugClient.attachRequest(args);
await initializePromise;
// Wait till we attach.
await attachedOutputReceived;
// Add a breakpoint.
const breakpointLocation = { path: fileToDebug, column: 1, line: 16 };
await debugClient.setBreakpointsRequest({
lines: [breakpointLocation.line],
breakpoints: [{ line: breakpointLocation.line, column: breakpointLocation.column }],
source: { path: breakpointLocation.path }
});
await debugClient.assertStoppedLocation('breakpoint', breakpointLocation);
// Get thread to continue.
const threads = await debugClient.threadsRequest();
expect(threads).to.be.not.equal(undefined, 'no threads response');
expect(threads.body.threads).to.be.lengthOf(1);
// Continue the program.
await debugClient.continueRequest({ threadId: threads.body.threads[0].id });
await lastOutputReceived;
await debugClient.waitForEvent('terminated');
});
});