Skip to content

Commit 3e451ac

Browse files
Eric Snowkarthiknadig
authored andcommitted
Enable testing of the new debug adapter. (microsoft#11908)
For microsoft#11704, microsoft#11733, and microsoft#9383 (and microsoft#4758?). We had a bunch of tests for the old debug adapter, but they were all disabled due to flakiness. Pretty much none of them are valid now that we've removed the old debug adapter. So we've removed all the old tests and added some new ones that run against the VS Code API (rather than using a DAP client).
1 parent 4b20034 commit 3e451ac

File tree

14 files changed

+708
-650
lines changed

14 files changed

+708
-650
lines changed

build/ci/vscode-python-pr-validation.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ name: '$(Year:yyyy).$(Month).0.$(BuildID)-pr'
77
pr:
88
autoCancel: true
99
branches:
10-
include: ['master', 'release*', 'ds*']
10+
include:
11+
- 'master'
12+
- 'release*'
13+
- 'ds*'
14+
- 'logging-changes-and-drop-old-debugger'
1115
paths:
1216
exclude: ['/news/1 Enhancements', '/news/2 Fixes', '/news/3 Code Health', '/.vscode']
1317

src/test/.vscode/launch.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"version": "0.1.0",
3+
"configurations": [
4+
{
5+
"name": "launch a file",
6+
"type": "python",
7+
"request": "launch",
8+
"program": "${file}",
9+
"console": "integratedTerminal"
10+
},
11+
{
12+
"name": "attach to a local port",
13+
"type": "python",
14+
"request": "attach",
15+
"port": 5678,
16+
"host": "localhost",
17+
"pathMappings": [
18+
{
19+
"localRoot": "${workspaceFolder}",
20+
"remoteRoot": "."
21+
}
22+
]
23+
},
24+
{
25+
"name": "attach to a local PID",
26+
"type": "python",
27+
"request": "attach",
28+
"processId": "${env:CI_DEBUGPY_PROCESS_ID}",
29+
"pathMappings": [
30+
{
31+
"localRoot": "${workspaceFolder}",
32+
"remoteRoot": "."
33+
}
34+
]
35+
}
36+
]
37+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// These configs are used in full-stack integration tests.
2+
// They mostly borrow from the code in src/client/debugger/extension/configuration/providers.
3+

src/test/common/platform/utils.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as fsextra from 'fs-extra';
88
import * as net from 'net';
99
import * as path from 'path';
1010
import * as tmpMod from 'tmp';
11+
import { CleanupFixture } from '../../fixtures';
1112

1213
// Note: all functional tests that trigger the VS Code "fs" API are
1314
// found in filesystem.test.ts.
@@ -94,36 +95,6 @@ export class SystemError extends Error {
9495
}
9596
}
9697

97-
export class CleanupFixture {
98-
private cleanups: (() => void | Promise<void>)[];
99-
constructor() {
100-
this.cleanups = [];
101-
}
102-
103-
public addCleanup(cleanup: () => void | Promise<void>) {
104-
this.cleanups.push(cleanup);
105-
}
106-
107-
public async cleanUp() {
108-
const cleanups = this.cleanups;
109-
this.cleanups = [];
110-
111-
return Promise.all(
112-
cleanups.map(async (cleanup, i) => {
113-
try {
114-
const res = cleanup();
115-
if (res) {
116-
await res;
117-
}
118-
} catch (err) {
119-
console.log(`cleanup ${i + 1} failed: ${err}`);
120-
console.log('moving on...');
121-
}
122-
})
123-
);
124-
}
125-
}
126-
12798
export class FSFixture extends CleanupFixture {
12899
private tempDir: string | undefined;
129100
private sockServer: net.Server | undefined;

src/test/debugger/attach.ptvsd.test.ts

Lines changed: 0 additions & 163 deletions
This file was deleted.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { expect } from 'chai';
7+
import * as fs from 'fs-extra';
8+
import * as path from 'path';
9+
import * as vscode from 'vscode';
10+
import { openFile } from '../../../common';
11+
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants';
12+
import { closeActiveWindows, initialize, initializeTest, IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../../../initialize';
13+
import { DebuggerFixture } from '../../utils';
14+
15+
const WS_ROOT = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test');
16+
17+
function resolveWSFile(wsRoot: string, ...filePath: string[]): string {
18+
return path.join(wsRoot, ...filePath);
19+
}
20+
21+
suite('Debugger Integration', () => {
22+
const file = resolveWSFile(WS_ROOT, 'pythonFiles', 'debugging', 'wait_for_file.py');
23+
const doneFile = resolveWSFile(WS_ROOT, 'should-not-exist');
24+
const outFile = resolveWSFile(WS_ROOT, 'output.txt');
25+
const resource = vscode.Uri.file(file);
26+
const defaultScriptArgs = [doneFile];
27+
let workspaceRoot: vscode.WorkspaceFolder;
28+
let fix: DebuggerFixture;
29+
suiteSetup(async function () {
30+
if (IS_MULTI_ROOT_TEST || !TEST_DEBUGGER) {
31+
// tslint:disable-next-line:no-invalid-this
32+
this.skip();
33+
}
34+
await initialize();
35+
const ws = vscode.workspace.getWorkspaceFolder(resource);
36+
workspaceRoot = ws!;
37+
expect(workspaceRoot).to.not.equal(undefined, 'missing workspace root');
38+
});
39+
setup(async () => {
40+
fix = new DebuggerFixture();
41+
await initializeTest();
42+
await openFile(file);
43+
});
44+
teardown(async () => {
45+
await fix.cleanUp();
46+
fix.addFSCleanup(outFile);
47+
await closeActiveWindows();
48+
});
49+
async function setDone() {
50+
await fs.writeFile(doneFile, '');
51+
fix.addFSCleanup(doneFile);
52+
}
53+
54+
type ConfigName = string;
55+
type ScriptArgs = string[];
56+
const tests: { [key: string]: [ConfigName, ScriptArgs] } = {
57+
// prettier-ignore
58+
'launch': ['launch a file', [...defaultScriptArgs, outFile]],
59+
// prettier-ignore
60+
'attach': ['attach to a local port', defaultScriptArgs],
61+
'attach to PID': ['attach to a local PID', defaultScriptArgs]
62+
// For now we do not worry about "test" debugging.
63+
};
64+
65+
suite('run to end', () => {
66+
for (const kind of Object.keys(tests)) {
67+
if (kind === 'attach to PID') {
68+
// Attach-to-pid is still a little finicky
69+
// so we're skipping it for now.
70+
continue;
71+
}
72+
const [configName, scriptArgs] = tests[kind];
73+
test(kind, async () => {
74+
const session = fix.resolveDebugger(configName, file, scriptArgs, workspaceRoot);
75+
await session.start();
76+
// Any debugger ops would go here.
77+
await new Promise((r) => setTimeout(r, 300)); // 0.3 seconds
78+
await setDone();
79+
const result = await session.waitUntilDone();
80+
81+
expect(result.exitCode).to.equal(0, 'bad exit code');
82+
const output = result.stdout !== '' ? result.stdout : fs.readFileSync(outFile).toString();
83+
expect(output.trim().endsWith('done!')).to.equal(true, `bad output\n${output}`);
84+
});
85+
}
86+
});
87+
88+
suite('handles breakpoint', () => {
89+
for (const kind of ['launch', 'attach']) {
90+
if (kind === 'attach') {
91+
// The test isn't working quite right for attach
92+
// so we skip it for now.
93+
continue;
94+
}
95+
const [configName, scriptArgs] = tests[kind];
96+
test(kind, async () => {
97+
const session = fix.resolveDebugger(configName, file, scriptArgs, workspaceRoot);
98+
const bp = session.addBreakpoint(file, 21); // line: "time.sleep()"
99+
await session.start();
100+
await session.waitForBreakpoint(bp);
101+
await setDone();
102+
const result = await session.waitUntilDone();
103+
104+
expect(result.exitCode).to.equal(0, 'bad exit code');
105+
const output = result.stdout !== '' ? result.stdout : fs.readFileSync(outFile).toString();
106+
expect(output.trim().endsWith('done!')).to.equal(true, `bad output\n${output}`);
107+
});
108+
}
109+
});
110+
});

0 commit comments

Comments
 (0)