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
2 changes: 1 addition & 1 deletion .github/workflows/server-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
with:
test_service_port: 8000
token: ${{ secrets.GITHUB_TOKEN }}
version: v3.0.0-alpha.6
version: v3
extra_params: '--skip-from=./packages/sdk/server-node/contract-tests/testharness-suppressions-fdv2.txt'

run-custom-socks-proxy-example:
Expand Down
16 changes: 4 additions & 12 deletions packages/sdk/server-node/contract-tests/src/sdkClientEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ export function makeSdkConfig(options: ServerSDKConfigParams, tag: string): LDOp
if (options.dataSystem.initializers) {
options.dataSystem.initializers.forEach((initializer) => {
if (initializer.polling) {
cf.baseUri = initializer.polling.baseUri;
cf.pollInterval = maybeTime(initializer.polling.pollIntervalMs);

const initializerOptions: PollingDataSourceConfiguration = {
type: 'polling',
baseUri: initializer.polling.baseUri,
pollInterval: maybeTime(initializer.polling.pollIntervalMs),
};

Expand All @@ -126,23 +124,17 @@ export function makeSdkConfig(options: ServerSDKConfigParams, tag: string): LDOp
if (options.dataSystem.synchronizers) {
options.dataSystem.synchronizers.forEach((synchronizer) => {
if (synchronizer.streaming) {
cf.streamUri = synchronizer.streaming.baseUri;

const synchronizerOptions: StreamingDataSourceConfiguration = {
type: 'streaming',
baseUri: synchronizer.streaming.baseUri,
streamInitialReconnectDelay: maybeTime(synchronizer.streaming.initialRetryDelayMs),
};

synchronizerOptions.streamInitialReconnectDelay = maybeTime(
synchronizer.streaming.initialRetryDelayMs,
);

dataSourceOptions.synchronizers.push(synchronizerOptions);
} else if (synchronizer.polling) {
cf.baseUri = synchronizer.polling.baseUri;
cf.pollInterval = maybeTime(synchronizer.polling.pollIntervalMs);

const synchronizerOptions: PollingDataSourceConfiguration = {
type: 'polling',
baseUri: synchronizer.polling.baseUri,
pollInterval: maybeTime(synchronizer.polling.pollIntervalMs),
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { LDOptions } from '../src/api/options/LDOptions';
import LDClientImpl from '../src/LDClientImpl';
import { createBasicPlatform } from './createBasicPlatform';

describe('given a custom FDv2 data system with per-source base URIs', () => {
const callbacks = {
onFailed: jest.fn(),
onError: jest.fn(),
onReady: jest.fn(),
onUpdate: jest.fn(),
hasEventListeners: jest.fn(),
};
let platform: any;
let client: LDClientImpl;

beforeEach(() => {
platform = createBasicPlatform();
// Failing the request is fine - the Requestor records the URL synchronously,
// before awaiting the response, so we can still assert on the target URL.
platform.requests.fetch = jest.fn(async () => {
throw new Error('no network in test');
});
// Minimal event-source mock so a streaming source can open without throwing.
platform.requests.createEventSource = jest.fn(() => ({
onopen: jest.fn(),
onclose: jest.fn(),
onerror: jest.fn(),
onretrying: jest.fn(),
addEventListener: jest.fn(),
close: jest.fn(),
}));
});

afterEach(() => {
client?.close();
jest.resetAllMocks();
});

it('routes a polling initializer to its per-source baseUri instead of the shared endpoint', async () => {
const options: LDOptions = {
sendEvents: false,
diagnosticOptOut: true,
dataSystem: {
dataSource: {
dataSourceOptionsType: 'custom',
initializers: [{ type: 'polling', baseUri: 'https://custom-init.example.com' }],
synchronizers: [],
},
},
};
client = new LDClientImpl('sdk-key', platform, options, callbacks);
await client.waitForInitialization({ timeout: 20 }).catch(() => {});

expect(platform.requests.fetch).toHaveBeenCalled();
const urls: string[] = platform.requests.fetch.mock.calls.map((c: any[]) => c[0] as string);
expect(urls.some((u) => u.startsWith('https://custom-init.example.com'))).toBe(true);
});

it('routes a streaming synchronizer to its per-source baseUri instead of the shared endpoint', async () => {
const options: LDOptions = {
sendEvents: false,
diagnosticOptOut: true,
dataSystem: {
dataSource: {
dataSourceOptionsType: 'custom',
initializers: [],
synchronizers: [{ type: 'streaming', baseUri: 'https://custom-stream.example.com' }],
},
},
};
client = new LDClientImpl('sdk-key', platform, options, callbacks);
// NOTE: `timeout` is in seconds (see LDWaitForInitializationOptions). Unlike the polling
// initializer test above, nothing here ever resolves/rejects initialization (the mocked
// createEventSource never fires onopen/onerror), so a `timeout: 20` (20 real seconds) would
// hang past jest's default per-test timeout. Use a short real timeout instead.
await client.waitForInitialization({ timeout: 0.02 }).catch(() => {});

expect(platform.requests.createEventSource).toHaveBeenCalled();
const urls: string[] = platform.requests.createEventSource.mock.calls.map(
(c: any[]) => c[0] as string,
);
expect(urls.some((u) => u.startsWith('https://custom-stream.example.com'))).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LDFlagDeliveryFallbackError,
LDLogger,
LDStreamingError,
ServiceEndpoints,
subsystem,
} from '@launchdarkly/js-sdk-common';

Expand Down Expand Up @@ -207,6 +208,33 @@ describe('given a stream processor with mock event source', () => {
);
});

it('prefers a per-source serviceEndpoints override over the clientContext streaming endpoint', () => {
const override = new ServiceEndpoints('https://override.stream.com', '');
const processor = new StreamingProcessorFDv2(
{
basicConfiguration: getBasicConfiguration(logger),
platform: basicPlatform,
},
'/all',
[],
{
authorization: 'my-sdk-key',
'user-agent': 'TestUserAgent/2.0.2',
'x-launchdarkly-wrapper': 'Rapper/1.2.3',
},
diagnosticsManager,
1,
override,
);
processor.start(jest.fn(), jest.fn());

expect(basicPlatform.requests.createEventSource).toHaveBeenLastCalledWith(
'https://override.stream.com/all',
expect.anything(),
);
processor.close();
});

it('adds listeners', () => {
expect(mockEventSource.addEventListener).toHaveBeenNthCalledWith(
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,3 +688,87 @@ describe('when setting different options', () => {
]);
});
});

// baseUri is a valid top-level LDOptions field, but standard/streamingOnly/pollingOnly
// dataSource shapes never read it -- each already gets its endpoint from
// Configuration.serviceEndpoints. The validator drops it and warns, mirroring how fdv1Fallback
// rejects fields outside its own table; custom mode and the top-level baseUri/streamUri/eventsUri
// options are unaffected.
it.each([
['standard', { dataSourceOptionsType: 'standard', baseUri: 'https://example.com' }],
[
'streamingOnly',
{ dataSourceOptionsType: 'streamingOnly', baseUri: 'https://example.com' },
],
['pollingOnly', { dataSourceOptionsType: 'pollingOnly', baseUri: 'https://example.com' }],
])('drops baseUri and warns on the %s dataSource shape', (_mode, dataSource) => {
const opts = withLogger({
dataSystem: { dataSource: dataSource as unknown as DataSourceOptions },
});
const config = new Configuration(opts);
expect((config.dataSystem!.dataSource as any).baseUri).toBeUndefined();
expect(logger(opts).getCount()).toEqual(1);
logger(opts).expectMessages([
{
level: LogLevel.Warn,
matches: /Ignoring unknown config option "dataSystem.dataSource.baseUri"/,
},
]);
});

it.each([
[
'standard',
{ dataSourceOptionsType: 'standard', pollInterval: 60, streamInitialReconnectDelay: 5 },
],
['streamingOnly', { dataSourceOptionsType: 'streamingOnly', streamInitialReconnectDelay: 5 }],
['pollingOnly', { dataSourceOptionsType: 'pollingOnly', pollInterval: 60 }],
])(
'still validates pollInterval/streamInitialReconnectDelay on the %s dataSource shape',
(_mode, dataSource) => {
const opts = withLogger({
dataSystem: { dataSource: dataSource as unknown as DataSourceOptions },
});
const config = new Configuration(opts);
const validated = config.dataSystem!.dataSource as any;
if ('pollInterval' in dataSource) {
expect(validated.pollInterval).toEqual((dataSource as any).pollInterval);
}
if ('streamInitialReconnectDelay' in dataSource) {
expect(validated.streamInitialReconnectDelay).toEqual(
(dataSource as any).streamInitialReconnectDelay,
);
}
expect(logger(opts).getCount()).toEqual(0);
},
);

it('does not affect baseUri inside a custom mode data source entry', () => {
const opts = withLogger({
dataSystem: {
dataSource: {
dataSourceOptionsType: 'custom',
initializers: [{ type: 'polling', baseUri: 'https://custom-init.example.com' }],
synchronizers: [{ type: 'streaming', baseUri: 'https://custom-sync.example.com' }],
} as unknown as DataSourceOptions,
},
});
const config = new Configuration(opts);
expect(config.dataSystem!.dataSource).toEqual({
dataSourceOptionsType: 'custom',
initializers: [{ type: 'polling', baseUri: 'https://custom-init.example.com' }],
synchronizers: [{ type: 'streaming', baseUri: 'https://custom-sync.example.com' }],
});
expect(logger(opts).getCount()).toEqual(0);
});

it('does not affect the top-level baseUri option', () => {
const opts = withLogger({
baseUri: 'https://example.com',
streamUri: 'https://stream.example.com',
eventsUri: 'https://events.example.com',
});
const config = new Configuration(opts);
expect(config.serviceEndpoints.polling).toEqual('https://example.com');
expect(logger(opts).getCount()).toEqual(0);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
CustomDataSourceOptions,
PollingDataSourceConfiguration,
PollingDataSourceOptions,
StandardDataSourceOptions,
StreamingDataSourceConfiguration,
StreamingDataSourceOptions,
} from '../../src/api/options/LDDataSystemOptions';

it('does not allow baseUri on StandardDataSourceOptions', () => {
const opts: StandardDataSourceOptions = {
dataSourceOptionsType: 'standard',
// @ts-expect-error standard mode already gets its endpoints from
// Configuration.serviceEndpoints; there is no per-source override
baseUri: 'https://example.com',
};
expect(opts).toBeTruthy();
});

it('does not allow baseUri on StreamingDataSourceOptions', () => {
const opts: StreamingDataSourceOptions = {
dataSourceOptionsType: 'streamingOnly',
// @ts-expect-error streamingOnly already gets its endpoint from
// Configuration.serviceEndpoints.streaming; there is no per-source override
baseUri: 'https://example.com',
};
expect(opts).toBeTruthy();
});

it('does not allow baseUri on PollingDataSourceOptions', () => {
const opts: PollingDataSourceOptions = {
dataSourceOptionsType: 'pollingOnly',
// @ts-expect-error pollingOnly already gets its endpoint from
// Configuration.serviceEndpoints.polling; there is no per-source override
baseUri: 'https://example.com',
};
expect(opts).toBeTruthy();
});

it('still allows baseUri on the custom mode streaming synchronizer configuration', () => {
const config: StreamingDataSourceConfiguration = {
type: 'streaming',
baseUri: 'https://custom-stream.example.com',
};
expect(config.baseUri).toBe('https://custom-stream.example.com');
});

it('still allows baseUri on the custom mode polling initializer/synchronizer configuration', () => {
const config: PollingDataSourceConfiguration = {
type: 'polling',
baseUri: 'https://custom-poll.example.com',
};
expect(config.baseUri).toBe('https://custom-poll.example.com');
});

it('still allows per-source baseUri inside a CustomDataSourceOptions data source', () => {
const custom: CustomDataSourceOptions = {
dataSourceOptionsType: 'custom',
initializers: [{ type: 'polling', baseUri: 'https://custom-init.example.com' }],
synchronizers: [{ type: 'streaming', baseUri: 'https://custom-sync.example.com' }],
};
expect(custom.initializers[0]).toMatchObject({ baseUri: 'https://custom-init.example.com' });
expect(custom.synchronizers[0]).toMatchObject({ baseUri: 'https://custom-sync.example.com' });
});
Loading
Loading