Skip to content

Commit

Permalink
Update status when summary is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Mar 29, 2022
1 parent 95ba4f8 commit cca50f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/core/server/status/plugins_status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,32 @@ describe('PluginStatusService', () => {
]);
});

it('updates when a plugin status observable emits with the same level but a different summary', async () => {
const service = new PluginsStatusService({
core$: coreAllAvailable$,
pluginDependencies: new Map([['a', []]]),
});
const statusUpdates: Array<Record<PluginName, ServiceStatus>> = [];
const subscription = service
.getAll$()
// the first emission happens right after core services emit (see explanation above)
.pipe(skip(1))
.subscribe((pluginStatuses) => statusUpdates.push(pluginStatuses));

const aStatus$ = new BehaviorSubject<ServiceStatus>({
level: ServiceStatusLevels.available,
summary: 'summary initial',
});
service.set('a', aStatus$);
aStatus$.next({ level: ServiceStatusLevels.available, summary: 'summary updated' });
subscription.unsubscribe();

expect(statusUpdates).toEqual([
{ a: { level: ServiceStatusLevels.available, summary: 'summary initial' } },
{ a: { level: ServiceStatusLevels.available, summary: 'summary updated' } },
]);
});

it('emits an unavailable status if first emission times out, then continues future emissions', async () => {
const service = new PluginsStatusService(
{
Expand Down
6 changes: 5 additions & 1 deletion src/core/server/status/plugins_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,15 @@ export class PluginsStatusService {
*/
private updatePluginReportedStatus(plugin: PluginName, reportedStatus: ServiceStatus): void {
const previousReportedLevel = this.pluginData[plugin].reportedStatus?.level;
const previousReportedSummary = this.pluginData[plugin].reportedStatus?.summary;

this.pluginData[plugin].reportedStatus = reportedStatus;
this.pluginStatus[plugin] = reportedStatus;

if (reportedStatus.level !== previousReportedLevel) {
if (
reportedStatus.level !== previousReportedLevel ||
reportedStatus.summary !== previousReportedSummary
) {
this.updatePluginsStatuses([plugin]);
}
}
Expand Down

0 comments on commit cca50f7

Please sign in to comment.