5
5
6
6
import * as assert from 'assert' ;
7
7
import { Event } from 'vs/base/common/event' ;
8
+ import { IChannel } from 'vs/base/parts/ipc/common/ipc' ;
8
9
import { Client } from 'vs/base/parts/ipc/node/ipc.cp' ;
9
10
import { getPathFromAmdModule } from 'vs/base/test/node/testUtils' ;
10
- import { TestServiceClient } from './testService' ;
11
+ import { ITestService , TestServiceClient } from './testService' ;
11
12
12
13
function createClient ( ) : Client {
13
14
return new Client ( getPathFromAmdModule ( require , 'bootstrap-fork' ) , {
@@ -20,39 +21,37 @@ suite('IPC, Child Process', function () {
20
21
this . slow ( 2000 ) ;
21
22
this . timeout ( 10000 ) ;
22
23
23
- test ( 'createChannel' , async ( ) => {
24
- const client = createClient ( ) ;
25
- const channel = client . getChannel ( 'test' ) ;
26
- const service = new TestServiceClient ( channel ) ;
24
+ let client : Client ;
25
+ let channel : IChannel ;
26
+ let service : ITestService ;
27
+
28
+ setup ( ( ) => {
29
+ client = createClient ( ) ;
30
+ channel = client . getChannel ( 'test' ) ;
31
+ service = new TestServiceClient ( channel ) ;
32
+ } ) ;
33
+
34
+ teardown ( ( ) => {
35
+ client . dispose ( ) ;
36
+ } ) ;
27
37
38
+ test ( 'createChannel' , async ( ) => {
28
39
const result = await service . pong ( 'ping' ) ;
29
40
assert . strictEqual ( result . incoming , 'ping' ) ;
30
41
assert . strictEqual ( result . outgoing , 'pong' ) ;
31
-
32
- client . dispose ( ) ;
33
42
} ) ;
34
43
35
44
test ( 'events' , async ( ) => {
36
- const client = createClient ( ) ;
37
- const channel = client . getChannel ( 'test' ) ;
38
- const service = new TestServiceClient ( channel ) ;
39
-
40
45
const event = Event . toPromise ( Event . once ( service . onMarco ) ) ;
41
46
const promise = service . marco ( ) ;
42
47
43
48
const [ promiseResult , eventResult ] = await Promise . all ( [ promise , event ] ) ;
44
49
45
50
assert . strictEqual ( promiseResult , 'polo' ) ;
46
51
assert . strictEqual ( eventResult . answer , 'polo' ) ;
47
-
48
- client . dispose ( ) ;
49
52
} ) ;
50
53
51
54
test ( 'event dispose' , async ( ) => {
52
- const client = createClient ( ) ;
53
- const channel = client . getChannel ( 'test' ) ;
54
- const service = new TestServiceClient ( channel ) ;
55
-
56
55
let count = 0 ;
57
56
const disposable = service . onMarco ( ( ) => count ++ ) ;
58
57
@@ -68,7 +67,5 @@ suite('IPC, Child Process', function () {
68
67
const answer_2 = await service . marco ( ) ;
69
68
assert . strictEqual ( answer_2 , 'polo' ) ;
70
69
assert . strictEqual ( count , 2 ) ;
71
-
72
- client . dispose ( ) ;
73
70
} ) ;
74
71
} ) ;
0 commit comments