Skip to content

Commit

Permalink
no setupReady startReady needed
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Jun 5, 2020
1 parent 7571f94 commit de2b2e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
24 changes: 6 additions & 18 deletions x-pack/plugins/reporting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import * as Rx from 'rxjs';
import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'src/core/server';
import { ReportingCore } from './';
import { initializeBrowserDriverFactory } from './browsers';
Expand All @@ -20,26 +21,13 @@ export class ReportingPlugin
private logger: LevelLogger;
private reportingCore?: ReportingCore;

private setupDone: (val?: unknown) => void = () => {};
private startDone: (val?: unknown) => void = () => {};
private setupPromise: Promise<unknown>;
private startPromise: Promise<unknown>;
// Setup some observables for modules that need to await setup/start
public readonly setup$ = new Rx.Subject<boolean>();
public readonly start$ = new Rx.Subject<boolean>();

constructor(context: PluginInitializerContext<ReportingConfigType>) {
this.logger = new LevelLogger(context.logger.get());
this.initializerContext = context;

// Setup some promises for modules that need to await setup/start
this.setupPromise = new Promise((r) => (this.setupDone = r));
this.startPromise = new Promise((r) => (this.startDone = r));
}

public async setupReady() {
return this.setupPromise;
}

public async startReady() {
return this.startPromise;
}

public setup(core: CoreSetup, plugins: ReportingSetupDeps) {
Expand All @@ -66,7 +54,7 @@ export class ReportingPlugin
this.reportingCore = reportingCore;

this.logger.debug('Setup complete');
this.setupDone();
this.setup$.next(true);
});

return {};
Expand Down Expand Up @@ -99,7 +87,7 @@ export class ReportingPlugin
runValidations(config, elasticsearch, browserDriverFactory, this.logger);

this.logger.debug('Start complete');
this.startDone();
this.start$.next(true);
});

return {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ jest.mock('../lib/enqueue_job');
jest.mock('../lib/validate');

import { of } from 'rxjs';
import { first } from 'rxjs/operators';
import { coreMock } from 'src/core/server/mocks';
import { ReportingConfig, ReportingCore } from '../';
import {
initializeBrowserDriverFactory,
HeadlessChromiumDriverFactory,
chromium,
HeadlessChromiumDriverFactory,
initializeBrowserDriverFactory,
} from '../browsers';
import { ReportingConfig, ReportingCore } from '../';
import { ReportingInternalSetup } from '../core';
import { ReportingPlugin } from '../plugin';
import { ReportingSetupDeps, ReportingStartDeps } from '../types';
Expand Down Expand Up @@ -68,9 +69,9 @@ const createMockReportingPlugin = async (config: ReportingConfig): Promise<Repor
};

plugin.setup(setupMock, createMockSetupDeps(setupMock));
await plugin.setupReady();
await plugin.setup$.pipe(first()).toPromise();
plugin.start(startMock, createMockStartDeps(startMock));
await plugin.startReady();
await plugin.start$.pipe(first()).toPromise();

return plugin;
};
Expand Down

0 comments on commit de2b2e0

Please sign in to comment.