Skip to content

Commit

Permalink
fix(core): avoid wrong featureServiceAlreadyRegistered logs (#560)
Browse files Browse the repository at this point in the history
If a feature service with dependencies is registered and those dependencies have already been registered beforehand, do not log that those dependent feature services are already registered and can not be re-registered. They are not tried to be registered anyway.
  • Loading branch information
unstubbable authored Feb 12, 2020
1 parent be84e93 commit 80eb1bf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
21 changes: 14 additions & 7 deletions packages/core/src/__tests__/feature-service-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,38 @@ describe('FeatureServiceRegistry', () => {
testRegistrationOrderABC();
});

it('does not register the already existing Feature Service "a"', () => {
it('does not register the already existing Feature Service "b"', () => {
featureServiceRegistry.registerFeatureServices(
[providerDefinitionA],
[providerDefinitionA, providerDefinitionB],
'test'
);
featureServiceRegistry.registerFeatureServices(
[providerDefinitionA],
[providerDefinitionB],
'test'
);

expect(providerDefinitionA.create.mock.calls).toEqual([
[{featureServices: {}}]
expect(providerDefinitionB.create.mock.calls).toEqual([
[{featureServices: {a: featureServiceA}}]
]);

expect(binderA.mock.calls).toEqual([]);
expect(binderA.mock.calls).toEqual([['b']]);
expect(binderB.mock.calls).toEqual([]);

expect(logger.info.mock.calls).toEqual([
[
'The Feature Service "a" has been successfully registered by registrant "test".'
],
[
'The required Feature Service "a" has been successfully bound to consumer "b".'
],
[
'The Feature Service "b" has been successfully registered by registrant "test".'
]
]);

expect(logger.warn.mock.calls).toEqual([
[
'The already registered Feature Service "a" could not be re-registered by registrant "test".'
'The already registered Feature Service "b" could not be re-registered by registrant "test".'
]
]);
});
Expand Down
40 changes: 23 additions & 17 deletions packages/core/src/feature-service-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,32 +308,38 @@ export class FeatureServiceRegistry {
): void {
const providerDefinition = providerDefinitionsById.get(providerId);

if (!providerDefinition) {
return;
}

if (this.sharedFeatureServices.has(providerId)) {
this.logger.warn(
Messages.featureServiceAlreadyRegistered(providerId, registrantId)
);
} else if (providerDefinition) {
this.validateExternals(providerDefinition);

const {featureServices} = this.bindFeatureServices(
providerDefinition,
providerId
);
return;
}

const sharedFeatureService = providerDefinition.create({featureServices});
this.validateExternals(providerDefinition);

this.validateFeatureServiceVersions(
sharedFeatureService,
providerId,
registrantId
);
const {featureServices} = this.bindFeatureServices(
providerDefinition,
providerId
);

this.sharedFeatureServices.set(providerId, sharedFeatureService);
const sharedFeatureService = providerDefinition.create({featureServices});

this.logger.info(
Messages.featureServiceSuccessfullyRegistered(providerId, registrantId)
);
}
this.validateFeatureServiceVersions(
sharedFeatureService,
providerId,
registrantId
);

this.sharedFeatureServices.set(providerId, sharedFeatureService);

this.logger.info(
Messages.featureServiceSuccessfullyRegistered(providerId, registrantId)
);
}

private bindFeatureService(
Expand Down

0 comments on commit 80eb1bf

Please sign in to comment.