Skip to content

Commit ff51b87

Browse files
authored
cleanup ipc integration tests (microsoft#165221)
1 parent 7fbec6d commit ff51b87

File tree

2 files changed

+31
-42
lines changed

2 files changed

+31
-42
lines changed

src/vs/base/parts/ipc/node/ipc.cp.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,8 @@ export class Client implements IChannelClient, IDisposable {
274274

275275
dispose() {
276276
this._onDidProcessExit.dispose();
277-
if (this.disposeDelayer) {
278-
this.disposeDelayer.cancel();
279-
this.disposeDelayer = undefined;
280-
}
277+
this.disposeDelayer?.cancel();
278+
this.disposeDelayer = undefined;
281279
this.disposeClient();
282280
this.activeRequests.clear();
283281
}

src/vs/base/parts/ipc/test/node/ipc.cp.integrationTest.ts

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as assert from 'assert';
7-
import { timeout } from 'vs/base/common/async';
7+
import { Event } from 'vs/base/common/event';
88
import { Client } from 'vs/base/parts/ipc/node/ipc.cp';
99
import { getPathFromAmdModule } from 'vs/base/test/node/testUtils';
1010
import { TestServiceClient } from './testService';
@@ -17,67 +17,58 @@ function createClient(): Client {
1717
}
1818

1919
suite('IPC, Child Process', function () {
20+
this.slow(2000);
2021
this.timeout(10000);
2122

22-
test('createChannel', () => {
23+
test('createChannel', async () => {
2324
const client = createClient();
2425
const channel = client.getChannel('test');
2526
const service = new TestServiceClient(channel);
2627

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');
3131

32-
return result.finally(() => client.dispose());
32+
client.dispose();
3333
});
3434

35-
test('events', () => {
35+
test('events', async () => {
3636
const client = createClient();
3737
const channel = client.getChannel('test');
3838
const service = new TestServiceClient(channel);
3939

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();
5749
});
5850

59-
test('event dispose', () => {
51+
test('event dispose', async () => {
6052
const client = createClient();
6153
const channel = client.getChannel('test');
6254
const service = new TestServiceClient(channel);
6355

6456
let count = 0;
6557
const disposable = service.onMarco(() => count++);
6658

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);
7062

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();
7567

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);
8071

81-
return result.finally(() => client.dispose());
72+
client.dispose();
8273
});
8374
});

0 commit comments

Comments
 (0)