-
Notifications
You must be signed in to change notification settings - Fork 27.9k
/
ipc.cp.integrationTest.ts
71 lines (57 loc) · 2.14 KB
/
ipc.cp.integrationTest.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { Event } from 'vs/base/common/event';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { Client } from 'vs/base/parts/ipc/node/ipc.cp';
import { ITestService, TestServiceClient } from './testService';
import { FileAccess } from 'vs/base/common/network';
function createClient(): Client {
return new Client(FileAccess.asFileUri('bootstrap-fork').fsPath, {
serverName: 'TestServer',
env: { VSCODE_AMD_ENTRYPOINT: 'vs/base/parts/ipc/test/node/testApp', verbose: true }
});
}
suite('IPC, Child Process', function () {
this.slow(2000);
this.timeout(10000);
let client: Client;
let channel: IChannel;
let service: ITestService;
setup(() => {
client = createClient();
channel = client.getChannel('test');
service = new TestServiceClient(channel);
});
teardown(() => {
client.dispose();
});
test('createChannel', async () => {
const result = await service.pong('ping');
assert.strictEqual(result.incoming, 'ping');
assert.strictEqual(result.outgoing, 'pong');
});
test('events', async () => {
const event = Event.toPromise(Event.once(service.onMarco));
const promise = service.marco();
const [promiseResult, eventResult] = await Promise.all([promise, event]);
assert.strictEqual(promiseResult, 'polo');
assert.strictEqual(eventResult.answer, 'polo');
});
test('event dispose', async () => {
let count = 0;
const disposable = service.onMarco(() => count++);
const answer = await service.marco();
assert.strictEqual(answer, 'polo');
assert.strictEqual(count, 1);
const answer_1 = await service.marco();
assert.strictEqual(answer_1, 'polo');
assert.strictEqual(count, 2);
disposable.dispose();
const answer_2 = await service.marco();
assert.strictEqual(answer_2, 'polo');
assert.strictEqual(count, 2);
});
});