check legacy service setup before start

This commit is contained in:
restrry 2019-04-25 12:37:10 +03:00
parent 62a67242c5
commit 255d3c3abc
3 changed files with 13 additions and 6 deletions

View file

@ -36,7 +36,7 @@ Array [
"debug": [MockFunction] {
"calls": Array [
Array [
"setting up legacy service",
"starting legacy service",
],
],
"results": Array [

View file

@ -414,3 +414,9 @@ describe('once LegacyService is set up in `devClusterMaster` mode', () => {
);
});
});
test('Cannot start without setup phase', async () => {
await expect(legacyService.start(startDeps)).rejects.toThrowErrorMatchingInlineSnapshot(
`"Legacy service is not setup yet."`
);
});

View file

@ -62,7 +62,11 @@ export class LegacyService implements CoreService {
this.setupDeps = setupDeps;
}
public async start(startDeps: CoreStart) {
this.log.debug('setting up legacy service');
const { setupDeps } = this;
if (!setupDeps) {
throw new Error('Legacy service is not setup yet.');
}
this.log.debug('starting legacy service');
const update$ = this.coreContext.configService.getConfig$().pipe(
tap(config => {
@ -85,10 +89,7 @@ export class LegacyService implements CoreService {
await this.createClusterManager(config);
return;
}
if (!this.setupDeps) {
throw new Error('Core setup contract is not defined');
}
return await this.createKbnServer(config, this.setupDeps, startDeps);
return await this.createKbnServer(config, setupDeps, startDeps);
})
)
.toPromise();