Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LDClientImpl } from '../src';
import { LDFeatureStore } from '../src/api/subsystems';
import { LDFeatureStore, LDStreamProcessor } from '../src/api/subsystems';
import NullUpdateProcessor from '../src/data_sources/NullUpdateProcessor';
import TestData from '../src/integrations/test_data/TestData';
import AsyncStoreFacade from '../src/store/AsyncStoreFacade';
Expand Down Expand Up @@ -158,6 +158,17 @@ describe('given an offline client', () => {
});
});

class InertUpdateProcessor implements LDStreamProcessor {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update processor that never finishes initialization.

// eslint-disable-next-line @typescript-eslint/no-unused-vars
start(fn?: ((err?: any) => void) | undefined) {
// Never initialize.
}

stop() {}

close() {}
}

describe('given a client and store that are uninitialized', () => {
let store: LDFeatureStore;
let client: LDClientImpl;
Expand All @@ -178,7 +189,7 @@ describe('given a client and store that are uninitialized', () => {
'sdk-key',
basicPlatform,
{
updateProcessor: new NullUpdateProcessor(),
updateProcessor: new InertUpdateProcessor(),
sendEvents: false,
featureStore: store,
},
Expand Down
8 changes: 5 additions & 3 deletions packages/shared/sdk-server/__tests__/LDClientImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ it('isOffline returns true in offline mode', (done) => {

describe('when waiting for initialization', () => {
let client: LDClientImpl;
let resolve: Function;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow manually completing initialization versus depending on predictable async execution.


beforeEach(() => {
client = new LDClientImpl(
Expand All @@ -62,9 +63,7 @@ describe('when waiting for initialization', () => {
{
updateProcessor: {
start: (fn: (err?: any) => void) => {
setTimeout(() => {
fn();
}, 0);
resolve = fn;
},
stop: () => {},
close: () => {},
Expand All @@ -81,17 +80,20 @@ describe('when waiting for initialization', () => {
});

it('resolves when ready', async () => {
resolve();
await client.waitForInitialization();
});

it('resolves immediately if the client is already ready', async () => {
resolve();
await client.waitForInitialization();
await client.waitForInitialization();
});

it('creates only one Promise', async () => {
const p1 = client.waitForInitialization();
const p2 = client.waitForInitialization();
resolve();
expect(p2).toBe(p1);
});
});
Expand Down