@@ -60,10 +60,10 @@ suite('Daemon - Python Daemon Pool', () => {
60
60
const pythonProc = spawn ( fullyQualifiedPythonPath , [ '-m' , 'datascience.daemon' ] , { env } ) ;
61
61
const connection = createMessageConnection ( new StreamMessageReader ( pythonProc . stdout ) , new StreamMessageWriter ( pythonProc . stdin ) ) ;
62
62
connection . listen ( ) ;
63
- disposables . push ( { dispose : ( ) => pythonProc . kill ( ) } ) ;
64
- disposables . push ( { dispose : ( ) => connection . dispose ( ) } ) ;
65
- // tslint:disable-next-line: no-any
66
- return { proc : pythonProc , dispose : noop , out : undefined as any } ;
63
+ disposables . push ( { dispose : ( ) => pythonProc . kill ( ) } ) ;
64
+ disposables . push ( { dispose : ( ) => connection . dispose ( ) } ) ;
65
+ // tslint:disable-next-line: no-any
66
+ return { proc : pythonProc , dispose : noop , out : undefined as any } ;
67
67
} ) ;
68
68
const options = { pythonPath : fullyQualifiedPythonPath , daemonModule : PythonDaemonModule , daemonCount : 2 , observableDaemonCount : 1 } ;
69
69
pythonDaemonPool = new DaemonPool ( options , instance ( pythonExecutionService ) , { } , 100 ) ;
@@ -78,7 +78,11 @@ suite('Daemon - Python Daemon Pool', () => {
78
78
async function getStdOutFromObservable ( output : ObservableExecutionResult < string > ) {
79
79
return new Promise < string > ( ( resolve , reject ) => {
80
80
const data : string [ ] = [ ] ;
81
- output . out . subscribe ( out => data . push ( out . out . trim ( ) ) , reject , ( ) => resolve ( data . join ( '' ) ) ) ;
81
+ output . out . subscribe (
82
+ out => data . push ( out . out . trim ( ) ) ,
83
+ reject ,
84
+ ( ) => resolve ( data . join ( '' ) )
85
+ ) ;
82
86
} ) ;
83
87
}
84
88
@@ -120,9 +124,9 @@ suite('Daemon - Python Daemon Pool', () => {
120
124
await assert . eventually . equal ( pythonDaemonPool . isModuleInstalled ( moduleName ) , expectedToBeInstalled ) ;
121
125
}
122
126
123
- test ( '\' pip\ ' module is installed' , async ( ) => testModuleInstalled ( 'pip' , true ) ) ;
124
- test ( '\' unittest\ ' module is installed' , async ( ) => testModuleInstalled ( 'unittest' , true ) ) ;
125
- test ( '\' VSCode-Python-Rocks\ ' module is not Installed' , async ( ) => testModuleInstalled ( 'VSCode-Python-Rocks' , false ) ) ;
127
+ test ( "' pip' module is installed" , async ( ) => testModuleInstalled ( 'pip' , true ) ) ;
128
+ test ( "' unittest' module is installed" , async ( ) => testModuleInstalled ( 'unittest' , true ) ) ;
129
+ test ( "' VSCode-Python-Rocks' module is not Installed" , async ( ) => testModuleInstalled ( 'VSCode-Python-Rocks' , false ) ) ;
126
130
127
131
test ( 'Execute a file and capture stdout (with unicode)' , async ( ) => {
128
132
const source = dedent `
@@ -242,7 +246,10 @@ suite('Daemon - Python Daemon Pool', () => {
242
246
await new Promise ( ( resolve , reject ) => {
243
247
output . out . subscribe ( out => outputsReceived . push ( out . out . trim ( ) ) , reject , resolve ) ;
244
248
} ) ;
245
- assert . deepEqual ( outputsReceived . filter ( item => item . length > 0 ) , [ '0' , '1' , '2' , '3' , '4' ] ) ;
249
+ assert . deepEqual (
250
+ outputsReceived . filter ( item => item . length > 0 ) ,
251
+ [ '0' , '1' , '2' , '3' , '4' ]
252
+ ) ;
246
253
} ) . timeout ( 1_000 ) ;
247
254
248
255
test ( 'Execute a file and throw exception if stderr is not empty' , async ( ) => {
@@ -279,21 +286,18 @@ suite('Daemon - Python Daemon Pool', () => {
279
286
// When using the python execution service, return a bogus value.
280
287
when ( pythonExecutionService . execObservable ( deepEqual ( [ fileToExecute ] ) , anything ( ) ) ) . thenCall ( ( ) => {
281
288
const observable = new Observable < Output < string > > ( s => {
282
- s . next ( { out : 'mypid' , source : 'stdout' } ) ;
289
+ s . next ( { out : 'mypid' , source : 'stdout' } ) ;
283
290
s . complete ( ) ;
284
291
} ) ;
285
- // tslint:disable-next-line: no-any
286
- return { proc : new EventEmitter ( ) as any , dispose : noop , out : observable } ;
292
+ // tslint:disable-next-line: no-any
293
+ return { proc : new EventEmitter ( ) as any , dispose : noop , out : observable } ;
287
294
} ) ;
288
295
// This will use a damon.
289
- const output1 = pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ;
296
+ const output1 = pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ;
290
297
// These two will use a python execution service.
291
- const output2 = pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ;
292
- const output3 = pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ;
293
- const [ result1 , result2 , result3 ] = await Promise . all ( [
294
- getStdOutFromObservable ( output1 ) , getStdOutFromObservable ( output2 ) ,
295
- getStdOutFromObservable ( output3 )
296
- ] ) ;
298
+ const output2 = pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ;
299
+ const output3 = pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ;
300
+ const [ result1 , result2 , result3 ] = await Promise . all ( [ getStdOutFromObservable ( output1 ) , getStdOutFromObservable ( output2 ) , getStdOutFromObservable ( output3 ) ] ) ;
297
301
298
302
// Two process ids are used to run the code (one process for a daemon, another for bogus puthon process).
299
303
expect ( result1 ) . to . not . equal ( 'mypid' ) ;
@@ -308,22 +312,22 @@ suite('Daemon - Python Daemon Pool', () => {
308
312
` ;
309
313
const fileToExecute = await createPythonFile ( source ) ;
310
314
// This will use a damon.
311
- const output1 = await getStdOutFromObservable ( pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ) ;
315
+ const output1 = await getStdOutFromObservable ( pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ) ;
312
316
// Wait for daemon to go into the pool.
313
317
await sleep ( 100 ) ;
314
318
// This will use a damon.
315
- const output2 = await getStdOutFromObservable ( pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ) ;
319
+ const output2 = await getStdOutFromObservable ( pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ) ;
316
320
// Wait for daemon to go into the pool.
317
321
await sleep ( 100 ) ;
318
322
// This will use a damon.
319
- const output3 = await getStdOutFromObservable ( pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ) ;
323
+ const output3 = await getStdOutFromObservable ( pythonDaemonPool . execObservable ( [ fileToExecute ] , { } ) ) ;
320
324
321
325
// The pid for all processes is the same.
322
326
// This means we're re-using the same daemon (process).
323
327
expect ( output1 ) . to . equal ( output2 ) ;
324
328
expect ( output1 ) . to . equal ( output3 ) ;
325
329
} ) . timeout ( 3_000 ) ;
326
- test ( 'Ensure two different daemons are used to execute code' , async ( ) => {
330
+ test ( 'Ensure two different daemons are used to execute code' , async ( ) => {
327
331
const source = dedent `
328
332
import os
329
333
import time
@@ -332,10 +336,7 @@ suite('Daemon - Python Daemon Pool', () => {
332
336
` ;
333
337
const fileToExecute = await createPythonFile ( source ) ;
334
338
335
- const [ output1 , output2 ] = await Promise . all ( [
336
- pythonDaemonPool . exec ( [ fileToExecute ] , { } ) ,
337
- pythonDaemonPool . exec ( [ fileToExecute ] , { } )
338
- ] ) ;
339
+ const [ output1 , output2 ] = await Promise . all ( [ pythonDaemonPool . exec ( [ fileToExecute ] , { } ) , pythonDaemonPool . exec ( [ fileToExecute ] , { } ) ] ) ;
339
340
340
341
// The pid for both processes will be different.
341
342
// This means we're running both in two separate daemons.
@@ -353,8 +354,8 @@ suite('Daemon - Python Daemon Pool', () => {
353
354
const fileToExecute1 = await createPythonFile ( source1 ) ;
354
355
355
356
let [ pid1 , pid2 ] = await Promise . all ( [
356
- pythonDaemonPool . exec ( [ fileToExecute1 ] , { } ) . then ( out => out . stdout . trim ( ) ) ,
357
- pythonDaemonPool . exec ( [ fileToExecute1 ] , { } ) . then ( out => out . stdout . trim ( ) )
357
+ pythonDaemonPool . exec ( [ fileToExecute1 ] , { } ) . then ( out => out . stdout . trim ( ) ) ,
358
+ pythonDaemonPool . exec ( [ fileToExecute1 ] , { } ) . then ( out => out . stdout . trim ( ) )
358
359
] ) ;
359
360
360
361
const processesUsedToRunCode = new Set < string > ( ) ;
@@ -374,8 +375,14 @@ suite('Daemon - Python Daemon Pool', () => {
374
375
` ;
375
376
const fileToExecute2 = await createPythonFile ( source2 ) ;
376
377
[ pid1 , pid2 ] = await Promise . all ( [
377
- pythonDaemonPool . exec ( [ fileToExecute1 ] , { } ) . then ( out => out . stdout . trim ( ) ) . catch ( ( ) => 'FAILED' ) ,
378
- pythonDaemonPool . exec ( [ fileToExecute2 ] , { } ) . then ( out => out . stdout . trim ( ) ) . catch ( ( ) => 'FAILED' )
378
+ pythonDaemonPool
379
+ . exec ( [ fileToExecute1 ] , { } )
380
+ . then ( out => out . stdout . trim ( ) )
381
+ . catch ( ( ) => 'FAILED' ) ,
382
+ pythonDaemonPool
383
+ . exec ( [ fileToExecute2 ] , { } )
384
+ . then ( out => out . stdout . trim ( ) )
385
+ . catch ( ( ) => 'FAILED' )
379
386
] ) ;
380
387
381
388
// Confirm that one of the executions failed due to an error.
@@ -386,13 +393,13 @@ suite('Daemon - Python Daemon Pool', () => {
386
393
expect ( processesUsedToRunCode . size ) . to . equal ( 2 ) ;
387
394
388
395
// Wait for a new daemon to be created.
389
- await waitForCondition ( async ( ) => ( createDaemonServicesSpy . callCount - daemonsCreated ) === 1 , 5_000 , 'Failed to create a new daemon' ) ;
396
+ await waitForCondition ( async ( ) => createDaemonServicesSpy . callCount - daemonsCreated === 1 , 5_000 , 'Failed to create a new daemon' ) ;
390
397
391
398
// Confirm we have two daemons by checking the Pids again.
392
399
// One of them will be new.
393
400
[ pid1 , pid2 ] = await Promise . all ( [
394
- pythonDaemonPool . exec ( [ fileToExecute1 ] , { } ) . then ( out => out . stdout . trim ( ) ) ,
395
- pythonDaemonPool . exec ( [ fileToExecute1 ] , { } ) . then ( out => out . stdout . trim ( ) )
401
+ pythonDaemonPool . exec ( [ fileToExecute1 ] , { } ) . then ( out => out . stdout . trim ( ) ) ,
402
+ pythonDaemonPool . exec ( [ fileToExecute1 ] , { } ) . then ( out => out . stdout . trim ( ) )
396
403
] ) ;
397
404
398
405
// Keep track of the pids.
0 commit comments