Skip to content

Commit 71444b5

Browse files
authored
Kill the test process on CI, 30s after completion (microsoft#4909)
* Revert * Kill the test process on CI, 10s after completion * Ooops * Close VSC gracefully * More changes * Some more changes * Logging * More ways to die than one... * Run here * Update to latest * Remove unwanted file * Fix merge * Fix linter issue * Do nothing * Fixes * Fixes to clearing timeout * Disable reporter * Import reporter * testing * Just log * Log just one item * Lets log more and see how this goes * CI * Fixes
1 parent 5bc23d5 commit 71444b5

13 files changed

Lines changed: 85 additions & 18 deletions

File tree

news/3 Code Health/4905.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Kill the test process on CI, 10s after the tests have completed.

package-lock.json

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@
23332333
"@types/loader-utils": "^1.1.3",
23342334
"@types/lodash": "^4.14.104",
23352335
"@types/md5": "^2.1.32",
2336-
"@types/mocha": "^2.2.48",
2336+
"@types/mocha": "^5.2.6",
23372337
"@types/node": "9.4.7",
23382338
"@types/promisify-node": "^0.4.0",
23392339
"@types/react": "^16.4.14",
@@ -2435,6 +2435,7 @@
24352435
"webpack-merge": "^4.1.4",
24362436
"webpack-node-externals": "^1.7.2",
24372437
"why-is-node-running": "^2.0.3",
2438+
"wtfnode": "^0.8.0",
24382439
"yargs": "^12.0.2"
24392440
},
24402441
"__metadata": {

src/client/application/diagnostics/checks/macPythonInterpreter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class InvalidMacPythonInterpreterService extends BaseDiagnosticsService {
5656
}
5757
public dispose() {
5858
if (this.timeOut) {
59-
this.timeOut.unref();
59+
clearTimeout(this.timeOut);
6060
this.timeOut = undefined;
6161
}
6262
}

src/client/debugger/debugAdapter/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class PythonDebugger extends DebugSession {
136136

137137
try {
138138
await this.debugServer!.client;
139-
timeout.unref();
139+
clearTimeout(timeout);
140140
if (!rejected) {
141141
resolve();
142142
}

src/client/providers/jediProxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class JediProxy implements Disposable {
185185
}
186186
}
187187
if (this.timer) {
188-
this.timer.unref();
188+
clearTimeout(this.timer);
189189
}
190190
this.killProcess();
191191
}
@@ -255,7 +255,7 @@ export class JediProxy implements Disposable {
255255

256256
await this.checkJediMemoryFootprintImpl();
257257
if (this.timer) {
258-
this.timer.unref();
258+
clearTimeout(this.timer);
259259
}
260260
this.timer = setTimeout(() => this.checkJediMemoryFootprint(), 15 * 1000);
261261
}

src/client/providers/linterProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class LinterProvider implements Disposable {
5353
// and then the extension is activated. So schedule linting pass now.
5454
if (!isTestExecution()) {
5555
const timer = setTimeout(() => this.engine.lintOpenPythonFiles().ignoreErrors(), 1200);
56-
this.disposables.push({ dispose: () => timer.unref() });
56+
this.disposables.push({ dispose: () => clearTimeout(timer) });
5757
}
5858
}
5959

src/client/unittests/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di
6767
this.workspaceTestManagerService.dispose();
6868
}
6969
if (this.configChangedTimer) {
70-
this.configChangedTimer.unref();
70+
clearTimeout(this.configChangedTimer);
7171
this.configChangedTimer = undefined;
7272
}
7373
if (this.autoDiscoverTimer) {
74-
this.autoDiscoverTimer.unref();
74+
clearTimeout(this.autoDiscoverTimer);
7575
this.autoDiscoverTimer = undefined;
7676
}
7777
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
// Custom reporter to ensure Mocha process exits when we're done with tests.
7+
// This is a hack, however for some reason the process running the tests do not exit.
8+
// The hack is to force it to die when tests are done, if this doesn't work we've got a bigger problem on our hands.
9+
10+
// tslint:disable:no-var-requires no-require-imports no-any no-console no-unnecessary-class no-default-export
11+
const log = require('why-is-node-running');
12+
const wtf = require('wtfnode');
13+
const mochaTests: any = require('mocha');
14+
const { EVENT_RUN_BEGIN, EVENT_RUN_END } = mochaTests.Runner.constants;
15+
class ExitReporter {
16+
constructor(runner: any) {
17+
console.log('Initialize Exit Reporter for Mocha (PVSC).');
18+
const stats = runner.stats;
19+
runner
20+
.once(EVENT_RUN_BEGIN, () => {
21+
console.info('Start Exit Reporter for Mocha.');
22+
})
23+
.once(EVENT_RUN_END, () => {
24+
process.stdout.cork();
25+
console.info('End Exit Reporter for Mocha.');
26+
process.stdout.write('If process does not die in 30s, then log and kill.');
27+
process.stdout.uncork();
28+
// NodeJs generally waits for pending timeouts, however the process running Mocha
29+
// No idea why it times, out. Once again, this is a hack.
30+
// Solution (i.e. hack), lets add a timeout with a delay of 30 seconds,
31+
// & if this process doesn't die, lets kill it.
32+
function die() {
33+
setTimeout(() => {
34+
console.info('Exiting from custom PVSC Mocha Reporter.');
35+
try {
36+
log();
37+
wtf();
38+
} catch (ex) {
39+
// Do nothing.
40+
}
41+
process.exit(stats.failures === 0 ? 0 : 1);
42+
try {
43+
// Lets just close VSC, hopefully that'll be sufficient (more graceful).
44+
const vscode = require('vscode');
45+
vscode.commands.executeCommand('workbench.action.closeWindow');
46+
} catch (ex) {
47+
// Do nothing.
48+
}
49+
}, 30000);
50+
}
51+
die();
52+
});
53+
}
54+
}
55+
56+
module.exports = ExitReporter;

src/test/debugger/run.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ suite('Run without Debugging', () => {
2424
this.skip();
2525
}
2626
await new Promise(resolve => setTimeout(resolve, 1000));
27-
const coverageDirectory = path.join(EXTENSION_ROOT_DIR, `debug_coverage_nodebug${this.currentTest.title}`);
27+
const coverageDirectory = path.join(EXTENSION_ROOT_DIR, `debug_coverage_nodebug${this.currentTest!.title}`);
2828
debugClient = await createDebugAdapter(coverageDirectory);
2929
});
3030
teardown(async () => {

0 commit comments

Comments
 (0)