4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import * as assert from 'assert' ;
7
- import { timeout } from 'vs/base/common/async ' ;
7
+ import { Event } from 'vs/base/common/event ' ;
8
8
import { Client } from 'vs/base/parts/ipc/node/ipc.cp' ;
9
9
import { getPathFromAmdModule } from 'vs/base/test/node/testUtils' ;
10
10
import { TestServiceClient } from './testService' ;
@@ -17,67 +17,58 @@ function createClient(): Client {
17
17
}
18
18
19
19
suite ( 'IPC, Child Process' , function ( ) {
20
+ this . slow ( 2000 ) ;
20
21
this . timeout ( 10000 ) ;
21
22
22
- test ( 'createChannel' , ( ) => {
23
+ test ( 'createChannel' , async ( ) => {
23
24
const client = createClient ( ) ;
24
25
const channel = client . getChannel ( 'test' ) ;
25
26
const service = new TestServiceClient ( channel ) ;
26
27
27
- const result = service . pong ( 'ping' ) . then ( r => {
28
- assert . strictEqual ( r . incoming , 'ping' ) ;
29
- assert . strictEqual ( r . outgoing , 'pong' ) ;
30
- } ) ;
28
+ const result = await service . pong ( 'ping' ) ;
29
+ assert . strictEqual ( result . incoming , 'ping' ) ;
30
+ assert . strictEqual ( result . outgoing , 'pong' ) ;
31
31
32
- return result . finally ( ( ) => client . dispose ( ) ) ;
32
+ client . dispose ( ) ;
33
33
} ) ;
34
34
35
- test ( 'events' , ( ) => {
35
+ test ( 'events' , async ( ) => {
36
36
const client = createClient ( ) ;
37
37
const channel = client . getChannel ( 'test' ) ;
38
38
const service = new TestServiceClient ( channel ) ;
39
39
40
- const event = new Promise ( ( c , e ) => {
41
- service . onMarco ( ( { answer } ) => {
42
- try {
43
- assert . strictEqual ( answer , 'polo' ) ;
44
- c ( undefined ) ;
45
- } catch ( err ) {
46
- e ( err ) ;
47
- }
48
- } ) ;
49
- } ) ;
50
-
51
- return timeout ( 100 ) . then ( ( ) => {
52
- const request = service . marco ( ) ;
53
- const result = Promise . all ( [ request , event ] ) ;
54
-
55
- return result . finally ( ( ) => client . dispose ( ) ) ;
56
- } ) ;
40
+ const event = Event . toPromise ( Event . once ( service . onMarco ) ) ;
41
+ const promise = service . marco ( ) ;
42
+
43
+ const [ promiseResult , eventResult ] = await Promise . all ( [ promise , event ] ) ;
44
+
45
+ assert . strictEqual ( promiseResult , 'polo' ) ;
46
+ assert . strictEqual ( eventResult . answer , 'polo' ) ;
47
+
48
+ client . dispose ( ) ;
57
49
} ) ;
58
50
59
- test ( 'event dispose' , ( ) => {
51
+ test ( 'event dispose' , async ( ) => {
60
52
const client = createClient ( ) ;
61
53
const channel = client . getChannel ( 'test' ) ;
62
54
const service = new TestServiceClient ( channel ) ;
63
55
64
56
let count = 0 ;
65
57
const disposable = service . onMarco ( ( ) => count ++ ) ;
66
58
67
- const result = service . marco ( ) . then ( async answer => {
68
- assert . strictEqual ( answer , 'polo' ) ;
69
- assert . strictEqual ( count , 1 ) ;
59
+ const answer = await service . marco ( ) ;
60
+ assert . strictEqual ( answer , 'polo' ) ;
61
+ assert . strictEqual ( count , 1 ) ;
70
62
71
- const answer_1 = await service . marco ( ) ;
72
- assert . strictEqual ( answer_1 , 'polo' ) ;
73
- assert . strictEqual ( count , 2 ) ;
74
- disposable . dispose ( ) ;
63
+ const answer_1 = await service . marco ( ) ;
64
+ assert . strictEqual ( answer_1 , 'polo' ) ;
65
+ assert . strictEqual ( count , 2 ) ;
66
+ disposable . dispose ( ) ;
75
67
76
- const answer_2 = await service . marco ( ) ;
77
- assert . strictEqual ( answer_2 , 'polo' ) ;
78
- assert . strictEqual ( count , 2 ) ;
79
- } ) ;
68
+ const answer_2 = await service . marco ( ) ;
69
+ assert . strictEqual ( answer_2 , 'polo' ) ;
70
+ assert . strictEqual ( count , 2 ) ;
80
71
81
- return result . finally ( ( ) => client . dispose ( ) ) ;
72
+ client . dispose ( ) ;
82
73
} ) ;
83
74
} ) ;
0 commit comments