Skip to content

Commit

Permalink
fix(solace-message-client): do not eagerly construct `SolaceMessageCl…
Browse files Browse the repository at this point in the history
…ient`

Previously, the SolaceMessageClient was constructed during application startup. This caused problems if OAuth authentication was enabled and the access token provider depended on services that were only available after the application was started. Instead, the SolaceMessageClient is now constructed on first use.

closes #53
  • Loading branch information
Marcarrian authored and danielwiehl committed Nov 16, 2022
1 parent 9905b3e commit 82f73ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import {provideLogger} from './logger';
@NgModule({})
export class SolaceMessageClientModule {

constructor(@Inject(FORROOT_GUARD) _guard: any, _solaceMessageClient: SolaceMessageClient /** eager construction */) { // eslint-disable-line @typescript-eslint/no-empty-function
constructor(@Inject(FORROOT_GUARD) _guard: any) { // eslint-disable-line @typescript-eslint/no-empty-function
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ describe('SolaceMessageClient', () => {
await expectAsync(solaceMessageClient.session).toBeResolved();
});

it('should not eagerly construct `SolaceMessageClient`', async () => {
TestBed.overrideProvider(SolaceMessageClient, {
useFactory: () => {
throw Error();
},
});
expect(() => TestBed.inject(SolaceMessageClientModule)).not.toThrowError();
});

it('should allow to disconnect and re-connect from the Solace message broker', async () => {
const solaceMessageClient = TestBed.inject(SolaceMessageClient);
await simulateLifecycleEvent(SessionEventCode.UP_NOTICE);
Expand Down

0 comments on commit 82f73ed

Please sign in to comment.