Skip to content
5 changes: 1 addition & 4 deletions contract-tests/sdkClientEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ export async function newSdkClientEntity(options) {
makeSdkConfig(options.configuration, options.tag),
);
try {
await Promise.race([
client.waitForInitialization(),
new Promise((resolve) => setTimeout(resolve, timeout)),
]);
await client.waitForInitialization({timeout: timeout});
} catch (_) {
// if waitForInitialization() rejects, the client failed to initialize, see next line
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('given test data with big segments', () => {
bigSegments: bigSegmentsConfig,
});

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

it('can require status', async () => {
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('given test data with big segments', () => {
logger,
});

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

it('Can observe the status change', (done) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('When using a file data source', () => {
sendEvents: false,
});

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });

const f1Var = await client.variation(flag1Key, { key: 'user1' }, 'default');
expect(f1Var).toEqual('off');
Expand All @@ -121,7 +121,7 @@ describe('When using a file data source', () => {
sendEvents: false,
});

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });

const f1Var = await client.variation(flag1Key, { key: 'user1' }, 'default');
expect(f1Var).toEqual('off');
Expand All @@ -143,7 +143,7 @@ describe('When using a file data source', () => {
sendEvents: false,
});

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });

const f1Var = await client.variation(flag1Key, { key: 'user1' }, 'default');
expect(f1Var).toEqual('off');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('When using a proxy', () => {

closeable.push(proxy, server, client);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
expect(client.initialized()).toBe(true);

// If the proxy server did not log a request then the SDK did not actually use the proxy
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('When using a proxy', () => {

closeable.push(proxy, server, events, client);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
expect(client.initialized()).toBe(true);

// If the proxy server did not log a request then the SDK did not actually use the proxy
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('When using a proxy', () => {

closeable.push(proxy, pollingServer, eventsServer, client);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
expect(client.initialized()).toBe(true);

// If the proxy server did not log a request then the SDK did not actually use the proxy
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/server-node/__tests__/LDClientNode.tls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('When using a TLS connection', () => {
tlsParams: { ca: server.certificate },
diagnosticOptOut: true,
});
await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

it('cannot connect via HTTPS to a server with a self-signed certificate, using default config', async () => {
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('When using a TLS connection', () => {
});

// this won't return until the stream receives the "put" event
await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
events.close();
});

Expand All @@ -85,7 +85,7 @@ describe('When using a TLS connection', () => {
logger,
});

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
client.identify({ key: 'user' });
await client.flush();

Expand Down
3 changes: 2 additions & 1 deletion packages/shared/mocks/src/streamingProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const setupMockStreamingProcessor = (
patchResponseJson?: any,
deleteResponseJson?: any,
errorTimeoutSeconds: number = 0,
initTimeoutMs: number = 0,
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 an initialization delay for testing.

) => {
MockStreamingProcessor.mockImplementation(
(
Expand All @@ -35,7 +36,7 @@ export const setupMockStreamingProcessor = (
}, errorTimeoutSeconds * 1000);
} else {
// execute put which will resolve the identify promise
setTimeout(() => listeners.get('put')?.processJson(putResponseJson));
setTimeout(() => listeners.get('put')?.processJson(putResponseJson), initTimeoutMs);

if (patchResponseJson) {
setTimeout(() => listeners.get('patch')?.processJson(patchResponseJson));
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/sdk-server-edge/src/api/LDClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Edge LDClient', () => {
const client = new LDClient('client-side-id', basicPlatform.info, {
sendEvents: true,
});
await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
const passedConfig = mockEventProcessor.mock.calls[0][0];

expect(passedConfig).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('given an LDClient with test data', () => {
makeCallbacks(true),
);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('given an LDClient with test data', () => {
makeCallbacks(true),
);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

afterEach(() => {
Expand Down Expand Up @@ -298,15 +298,15 @@ describe('given an offline client', () => {
});

it('returns the default value for variation', async () => {
await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
td.update(td.flag('flagkey').variations('value').variationForAll(0));
const result = await client.variation('flagkey', defaultUser, 'default');
expect(result).toEqual('default');
expect(logger.getCount(LogLevel.Info)).toEqual(1);
});

it('returns the default value for variationDetail', async () => {
await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
td.update(td.flag('flagkey').variations('value').variationForAll(0));
const result = await client.variationDetail('flagkey', defaultUser, 'default');
expect(result).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('given a client with mock event processor', () => {
},
makeCallbacks(false),
);
await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/sdk-server/__tests__/LDClient.hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('given an LDClient with test data', () => {
makeCallbacks(true),
);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

afterEach(() => {
Expand Down Expand Up @@ -361,7 +361,7 @@ it('can add a hook after initialization', async () => {
makeCallbacks(true),
);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });

td.update(td.flag('flagKey').booleanFlag().on(true));
const testHook = new TestHook();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('given an LDClient with test data', () => {
callbacks,
);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('given test data with big segments', () => {
makeCallbacks(true),
);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

afterEach(() => {
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('given test data with big segments', () => {
makeCallbacks(true),
);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

afterEach(() => {
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('given test data with big segments', () => {
makeCallbacks(true),
);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

afterEach(() => {
Expand All @@ -189,7 +189,7 @@ describe('given test data with big segments', () => {
makeCallbacks(true),
);

await client.waitForInitialization();
await client.waitForInitialization({ timeout: 10 });
});

afterEach(() => {
Expand Down
Loading