5
5
import { assert } from 'chai' ;
6
6
import { Uri } from 'vscode' ;
7
7
8
- import { ChildProcess } from 'child_process' ;
9
8
import { IFileSystem } from '../../client/common/platform/types' ;
10
9
import { IPythonExecutionFactory } from '../../client/common/process/types' ;
11
10
import { Resource } from '../../client/common/types' ;
@@ -14,7 +13,7 @@ import { JupyterZMQBinariesNotFoundError } from '../../client/datascience/jupyte
14
13
import { KernelLauncher } from '../../client/datascience/kernel-launcher/kernelLauncher' ;
15
14
import { IKernelConnection , IKernelFinder } from '../../client/datascience/kernel-launcher/types' ;
16
15
import { InterpreterType , PythonInterpreter } from '../../client/interpreter/contracts' ;
17
- import { PYTHON_PATH , sleep } from '../common' ;
16
+ import { PYTHON_PATH , sleep , waitForCondition } from '../common' ;
18
17
import { DataScienceIocContainer } from './dataScienceIocContainer' ;
19
18
20
19
suite ( 'Kernel Launcher' , ( ) => {
@@ -50,25 +49,49 @@ suite('Kernel Launcher', () => {
50
49
this . skip ( ) ;
51
50
} else {
52
51
const kernel = await kernelLauncher . launch ( resource , kernelName ) ;
52
+ const exited = new Promise < boolean > ( ( resolve ) => kernel . exited ( ( ) => resolve ( true ) ) ) ;
53
53
54
54
assert . isOk < IKernelConnection | undefined > ( kernel . connection , 'Connection not found' ) ;
55
- assert . isOk < ChildProcess | undefined > ( kernel . process , 'Child Process not found' ) ;
56
55
56
+ // It should not exit.
57
+ assert . isRejected (
58
+ waitForCondition ( ( ) => exited , 5_000 , 'Timeout' ) ,
59
+ 'Timeout'
60
+ ) ;
61
+
62
+ // Upon disposing, we should get an exit event within 100ms or less.
63
+ // If this happens, then we know a process existed.
57
64
kernel . dispose ( ) ;
65
+ assert . isRejected (
66
+ waitForCondition ( ( ) => exited , 100 , 'Timeout' ) ,
67
+ 'Timeout'
68
+ ) ;
58
69
}
59
- } ) ;
70
+ } ) . timeout ( 10_000 ) ;
60
71
61
72
test ( 'Launch from PythonInterpreter' , async function ( ) {
62
73
if ( ! process . env . VSCODE_PYTHON_ROLLING ) {
63
74
// tslint:disable-next-line: no-invalid-this
64
75
this . skip ( ) ;
65
76
} else {
66
77
const kernel = await kernelLauncher . launch ( pythonInterpreter , kernelName ) ;
78
+ const exited = new Promise < boolean > ( ( resolve ) => kernel . exited ( ( ) => resolve ( true ) ) ) ;
79
+
80
+ // It should not exit.
81
+ assert . isRejected (
82
+ waitForCondition ( ( ) => exited , 5_000 , 'Timeout' ) ,
83
+ 'Timeout'
84
+ ) ;
67
85
68
86
assert . isOk < IKernelConnection | undefined > ( kernel . connection , 'Connection not found' ) ;
69
- assert . isOk < ChildProcess | undefined > ( kernel . process , 'Child Process not found' ) ;
70
87
88
+ // Upon disposing, we should get an exit event within 100ms or less.
89
+ // If this happens, then we know a process existed.
71
90
kernel . dispose ( ) ;
91
+ assert . isRejected (
92
+ waitForCondition ( ( ) => exited , 100 , 'Timeout' ) ,
93
+ 'Timeout'
94
+ ) ;
72
95
}
73
96
} ) ;
74
97
0 commit comments