1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
1
4
'use strict' ;
5
+
2
6
import { inject , injectable } from 'inversify' ;
7
+ import { Socket } from 'net' ;
3
8
import * as path from 'path' ;
4
9
import { EXTENSION_ROOT_DIR } from '../../common/constants' ;
5
10
import { noop } from '../../common/core.utils' ;
6
11
import { ILogger } from '../../common/types' ;
7
12
import { IServiceContainer } from '../../ioc/types' ;
8
13
import { UNITTEST_PROVIDER } from '../common/constants' ;
9
14
import { Options } from '../common/runner' ;
10
- import { ITestDebugLauncher , ITestManager , ITestResultsService , ITestRunner , IUnitTestSocketServer , LaunchOptions , TestRunOptions , Tests , TestStatus , TestsToRun } from '../common/types' ;
15
+ import {
16
+ ITestDebugLauncher , ITestManager , ITestResultsService ,
17
+ ITestRunner , IUnitTestSocketServer , LaunchOptions ,
18
+ TestRunOptions , Tests , TestStatus
19
+ } from '../common/types' ;
11
20
import { IArgumentsHelper , ITestManagerRunner , IUnitTestHelper } from '../types' ;
12
21
13
22
type TestStatusMap = {
@@ -42,7 +51,9 @@ export class TestManagerRunner implements ITestManagerRunner {
42
51
this . logger = this . serviceContainer . get < ILogger > ( ILogger ) ;
43
52
this . helper = this . serviceContainer . get < IUnitTestHelper > ( IUnitTestHelper ) ;
44
53
}
45
- public async runTest ( testResultsService : ITestResultsService , options : TestRunOptions , testManager : ITestManager ) : Promise < Tests > {
54
+
55
+ // tslint:disable-next-line:max-func-body-length
56
+ public async runTest ( testResultsService : ITestResultsService , options : TestRunOptions , testManager : ITestManager ) : Promise < Tests > {
46
57
options . tests . summary . errors = 0 ;
47
58
options . tests . summary . failures = 0 ;
48
59
options . tests . summary . passed = 0 ;
@@ -53,7 +64,6 @@ export class TestManagerRunner implements ITestManagerRunner {
53
64
this . server . on ( 'log' , noop ) ;
54
65
this . server . on ( 'connect' , noop ) ;
55
66
this . server . on ( 'start' , noop ) ;
56
- this . server . on ( 'socket.disconnected' , noop ) ;
57
67
this . server . on ( 'result' , ( data : ITestData ) => {
58
68
const test = options . tests . testFunctions . find ( t => t . testFunction . nameToRun === data . test ) ;
59
69
const statusDetails = outcomeMapping . get ( data . outcome ) ! ;
@@ -73,6 +83,15 @@ export class TestManagerRunner implements ITestManagerRunner {
73
83
}
74
84
} ) ;
75
85
86
+ this . server . on ( 'socket.disconnected' , ( socket : Socket , isSocketDestroyed : boolean ) => {
87
+ this . server . removeAllListeners ( 'error' ) ;
88
+ this . server . removeAllListeners ( 'log' ) ;
89
+ this . server . removeAllListeners ( 'connect' ) ;
90
+ this . server . removeAllListeners ( 'start' ) ;
91
+ this . server . removeAllListeners ( 'result' ) ;
92
+ this . server . removeAllListeners ( 'socket.disconnected' ) ;
93
+ } ) ;
94
+
76
95
const port = await this . server . start ( ) ;
77
96
const testPaths : string [ ] = this . helper . getIdsOfTestsToRun ( options . tests , options . testsToRun ! ) ;
78
97
for ( let counter = 0 ; counter < testPaths . length ; counter += 1 ) {
@@ -139,6 +158,7 @@ export class TestManagerRunner implements ITestManagerRunner {
139
158
testResultsService . updateResults ( options . tests ) ;
140
159
return options . tests ;
141
160
}
161
+
142
162
private buildTestArgs ( args : string [ ] ) : string [ ] {
143
163
const startTestDiscoveryDirectory = this . helper . getStartDirectory ( args ) ;
144
164
let pattern = 'test*.py' ;
0 commit comments