forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc.unit.test.ts
More file actions
52 lines (41 loc) · 1.58 KB
/
proc.unit.test.ts
File metadata and controls
52 lines (41 loc) · 1.58 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
// 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 { ChildProcess, spawn } from 'child_process';
import { ProcessService } from '../../../client/common/process/proc';
import { createDeferred, Deferred } from '../../../client/common/utils/async';
import { PYTHON_PATH } from '../../common';
interface IProcData {
proc: ChildProcess;
exited: Deferred<Boolean>;
}
suite('Process - Process Service', function() {
// tslint:disable-next-line:no-invalid-this
this.timeout(5000);
const procsToKill: IProcData[] = [];
teardown(() => {
procsToKill.forEach(p => {
if (!p.exited.resolved) {
p.proc.kill();
}
});
});
function spawnProc(): IProcData {
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));
procsToKill.push({ proc, exited });
return procsToKill[procsToKill.length - 1];
}
test('Process is killed', async () => {
const proc = spawnProc();
ProcessService.kill(proc.proc.pid);
expect(await proc.exited.promise).to.equal(true, 'process did not die');
});
test('Process is alive', async () => {
const proc = spawnProc();
expect(ProcessService.isAlive(proc.proc.pid)).to.equal(true, 'process is not alive');
});
});