提交 f0b76b7e 编写于 作者: M Matt Bierner

Use async/await in tests

上级 c9c8dbbc
......@@ -60,20 +60,18 @@ suite('IPC, Child Process', () => {
let count = 0;
const disposable = service.onMarco(() => count++);
const result = service.marco().then(answer => {
const result = service.marco().then(async answer => {
assert.equal(answer, 'polo');
assert.equal(count, 1);
return service.marco().then(answer => {
assert.equal(answer, 'polo');
assert.equal(count, 2);
disposable.dispose();
const answer_1 = await service.marco();
assert.equal(answer_1, 'polo');
assert.equal(count, 2);
disposable.dispose();
return service.marco().then(answer => {
assert.equal(answer, 'polo');
assert.equal(count, 2);
});
});
const answer_2 = await service.marco();
assert.equal(answer_2, 'polo');
assert.equal(count, 2);
});
return always(result, () => client.dispose());
......
......@@ -38,29 +38,28 @@ suite('IPC, Socket Protocol', () => {
stream = <any>new MockDuplex();
});
test('read/write', () => {
test('read/write', async () => {
const a = new Protocol(stream);
const b = new Protocol(stream);
return new Promise(resolve => {
await new Promise(resolve => {
const sub = b.onMessage(data => {
sub.dispose();
assert.equal(data.toString(), 'foobarfarboo');
resolve(null);
});
a.send(Buffer.from('foobarfarboo'));
}).then(() => {
return new Promise(resolve => {
const sub = b.onMessage(data => {
sub.dispose();
assert.equal(data.readInt8(0), 123);
resolve(null);
});
const buffer = Buffer.allocUnsafe(1);
buffer.writeInt8(123, 0);
a.send(buffer);
});
return new Promise(resolve => {
const sub_1 = b.onMessage(data => {
sub_1.dispose();
assert.equal(data.readInt8(0), 123);
resolve(null);
});
const buffer = Buffer.allocUnsafe(1);
buffer.writeInt8(123, 0);
a.send(buffer);
});
});
......
......@@ -231,23 +231,27 @@ suite('Base IPC', function () {
server.dispose();
});
test('call success', function () {
return ipcService.marco()
.then(r => assert.equal(r, 'polo'));
test('call success', async function () {
const r = await ipcService.marco();
return assert.equal(r, 'polo');
});
test('call error', function () {
return ipcService.error('nice error').then(
() => assert.fail('should not reach here'),
err => assert.equal(err.message, 'nice error')
);
test('call error', async function () {
try {
await ipcService.error('nice error');
return assert.fail('should not reach here');
} catch (err) {
return assert.equal(err.message, 'nice error');
}
});
test('cancel call with cancelled cancellation token', function () {
return ipcService.neverCompleteCT(CancellationToken.Cancelled).then(
_ => assert.fail('should not reach here'),
err => assert(err.message === 'Canceled')
);
test('cancel call with cancelled cancellation token', async function () {
try {
await ipcService.neverCompleteCT(CancellationToken.Cancelled);
return assert.fail('should not reach here');
} catch (err) {
return assert(err.message === 'Canceled');
}
});
test('cancel call with cancellation token (sync)', function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册