6
6
import assert from 'assert'
7
7
import * as os from 'os'
8
8
import * as path from 'path'
9
+ import * as sinon from 'sinon'
9
10
import { makeTemporaryToolkitFolder , tryRemoveFolder } from '../../../shared/filesystemUtilities'
10
11
import { ChildProcess , ChildProcessTracker , eof , ProcessStats } from '../../../shared/utilities/processUtils'
11
12
import { sleep } from '../../../shared/utilities/timeoutUtils'
@@ -14,7 +15,6 @@ import { fs } from '../../../shared'
14
15
import * as FakeTimers from '@sinonjs/fake-timers'
15
16
import { installFakeClock } from '../../testUtil'
16
17
import { isWin } from '../../../shared/vscode/env'
17
- import Sinon from 'sinon'
18
18
import { assertLogsContain } from '../../globalSetup.test'
19
19
20
20
describe ( 'ChildProcess' , async function ( ) {
@@ -368,6 +368,14 @@ describe('ChildProcessTracker', function () {
368
368
tracker = new ChildProcessTracker ( )
369
369
} )
370
370
371
+ afterEach ( function ( ) {
372
+ tracker . clear ( )
373
+ } )
374
+
375
+ after ( function ( ) {
376
+ clock . uninstall ( )
377
+ } )
378
+
371
379
it ( `removes stopped processes every ${ ChildProcessTracker . pollingInterval / 1000 } seconds` , async function ( ) {
372
380
// Start a 'sleep' command, check it only removes after we stop it.
373
381
const childProcess = new ChildProcess ( getSleepCmd ( ) , [ '90' ] )
@@ -388,30 +396,24 @@ describe('ChildProcessTracker', function () {
388
396
const childProcess2 = new ChildProcess ( getSleepCmd ( ) , [ '90' ] )
389
397
childProcess1 . run ( ) . catch ( ( ) => assert . fail ( 'sleep command threw an error' ) )
390
398
childProcess2 . run ( ) . catch ( ( ) => assert . fail ( 'sleep command threw an error' ) )
391
-
392
399
tracker . add ( childProcess1 )
393
400
tracker . add ( childProcess2 )
394
401
395
402
assert . strictEqual ( tracker . has ( childProcess1 ) , true , 'Missing first process' )
396
403
assert . strictEqual ( tracker . has ( childProcess2 ) , true , 'Missing second process' )
397
- assert . strictEqual ( tracker . size ( ) , 2 )
398
404
399
405
childProcess1 . stop ( )
400
- await clock . tickAsync ( ChildProcessTracker . pollingInterval + 1 )
406
+ await clock . tickAsync ( ChildProcessTracker . pollingInterval )
401
407
assert . strictEqual ( tracker . has ( childProcess2 ) , true , 'first process was not removed after stopping it' )
402
408
assert . strictEqual ( tracker . size ( ) , 1 )
403
-
404
- childProcess2 . stop ( )
405
- await clock . tickAsync ( ChildProcessTracker . pollingInterval + 1 )
406
- assert . strictEqual ( tracker . size ( ) , 0 , 'second process was not removed after stopping it' )
407
409
} )
408
410
409
411
it ( 'logs a warning message when system usage exceeds threshold' , async function ( ) {
410
412
const childProcess = new ChildProcess ( getSleepCmd ( ) , [ '90' ] )
411
413
childProcess . run ( ) . catch ( ( ) => assert . fail ( 'sleep command threw an error' ) )
412
414
tracker . add ( childProcess )
413
415
414
- const usageMock = Sinon . stub ( ChildProcessTracker . prototype , 'getUsage' )
416
+ const usageMock = sinon . stub ( ChildProcessTracker . prototype , 'getUsage' )
415
417
const highCpu : ProcessStats = {
416
418
cpu : ChildProcessTracker . thresholds . cpu + 1 ,
417
419
memory : 0 ,
@@ -442,6 +444,6 @@ describe('ChildProcessTracker', function () {
442
444
await clock . tickAsync ( ChildProcessTracker . pollingInterval )
443
445
assertLogsContain ( 'exceeded time threshold' , false , 'warn' )
444
446
445
- usageMock . restore ( )
447
+ sinon . restore ( )
446
448
} )
447
449
} )
0 commit comments