Skip to content

Commit

Permalink
test(rpc/integration): add test case for service shutdown process on …
Browse files Browse the repository at this point in the history
…break connection
  • Loading branch information
CheerlessCloud committed Oct 4, 2018
1 parent 4097905 commit 473b7f6
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions test/rpc-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import test from 'ava';
import uuid from 'uuid/v4';
import EError from 'eerror';
import { stub } from 'sinon';
import RpcClient from '../src/Client';
import RpcService from '../src/Service';
import RpcHandler from '../src/rpc/Handler';
Expand Down Expand Up @@ -37,13 +38,13 @@ test.beforeEach(async t => {
test.afterEach(async t => {
const { client, service } = t.context;

if (service.destroy) {
try {
await service.destroy();
}
} catch (err) {} // eslint-disable-line no-empty

if (client.destroy) {
try {
await client.destroy();
}
} catch (err) {} // eslint-disable-line no-empty
});

test('service and client basic integration', async t => {
Expand Down Expand Up @@ -224,3 +225,32 @@ test('catch error throwed in handler constructor', async t => {

await t.throws(client.call('myAction', { foo: '42' }), 'Error on construct class handler');
});

test('service shutdown process on break connection with interventSignalInterceptors', async t => {
t.plan(2);
const { service } = t.context;

await service.addHandler(
class extends RpcHandler {
async handle() {} // eslint-disable-line no-empty-function
},
);

await service.ensureConnection();

await service.interventSignalInterceptors({
stopSignal: 'SIGINT',
gracefulStopTimeout: 1000,
});

service.setErrorHandler(err => t.is(err.message, 'ECONNRESET'));
const processExitStub = stub(global.process, 'exit');

service._adapter._channel.connection.stream.destroy(new Error('ECONNRESET'));

await new Promise(resolve => setTimeout(() => resolve(), 100));

t.true(processExitStub.calledOnceWith(0));

processExitStub.restore();
});

0 comments on commit 473b7f6

Please sign in to comment.