forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc.unit.test.ts
More file actions
53 lines (42 loc) · 1.62 KB
/
proc.unit.test.ts
File metadata and controls
53 lines (42 loc) · 1.62 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// tslint:disable:no-any max-func-body-length no-invalid-this max-classes-per-file
import { expect } from 'chai';
import { spawn } from 'child_process';
import { ProcessService } from '../../../client/common/process/proc';
import { createDeferred } from '../../../client/common/utils/async';
import { PYTHON_PATH } from '../../common';
suite('Process - Process Service', function () {
// tslint:disable-next-line:no-invalid-this
this.timeout(5000);
let procIdsToKill: number[] = [];
teardown(() => {
// tslint:disable-next-line:no-require-imports
const killProcessTree = require('tree-kill');
procIdsToKill.forEach(pid => {
try {
killProcessTree(pid);
} catch {
// Ignore.
}
});
procIdsToKill = [];
});
function spawnProc() {
const proc = spawn(PYTHON_PATH, ['-c', 'while(True): import time;time.sleep(0.5);print(1)']);
const exited = createDeferred<Boolean>();
proc.on('exit', () => exited.resolve(true));
procIdsToKill.push(proc.pid);
return { pid: proc.pid, exited: exited.promise };
}
test('Process is killed', async () => {
const proc = spawnProc();
ProcessService.kill(proc.pid);
expect(await proc.exited).to.equal(true, 'process did not die');
});
test('Process is alive', async () => {
const proc = spawnProc();
expect(ProcessService.isAlive(proc.pid)).to.equal(true, 'process is not alive');
});
});