Skip to content

Commit 34e0170

Browse files
Update tests
1 parent da48da4 commit 34e0170

File tree

5 files changed

+69
-26
lines changed

5 files changed

+69
-26
lines changed

CHANGES.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
11.5.0 (August XX, 2025)
2-
- Added `factory.getCache()` method for standalone server-side SDKs, which returns the rollout plan snapshot from the storage.
3-
- Added `preloadedData` configuration option for standalone client-side SDKs, which allows preloading the SDK storage with a snapshot of the rollout plan.
2+
- Added `factory.getRolloutPlan()` method for standalone server-side SDKs, which returns the rollout plan snapshot from the storage.
3+
- Added `initialRolloutPlan` configuration option for standalone client-side SDKs, which allows preloading the SDK storage with a snapshot of the rollout plan.
44

55
11.4.1 (June 3, 2025)
66
- Updated @splitsoftware/splitio-commons package to version 2.4.1, which improves the Proxy fallback to flag spec version 1.2 by handling the case when the Proxy does not return an end-of-stream marker in 400 status code responses.

src/__tests__/browserSuites/ready-from-cache.spec.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ const alwaysOnSplitInverted = JSON.stringify({
2020
'killed': false,
2121
'defaultTreatment': 'off',
2222
'conditions': [
23+
{
24+
'matcherGroup': {
25+
'combiner': 'AND',
26+
'matchers': [
27+
{
28+
'matcherType': 'IN_SEGMENT',
29+
'userDefinedSegmentMatcherData': {
30+
'segmentName': 'employees'
31+
},
32+
}
33+
]
34+
},
35+
'partitions': [
36+
{
37+
'treatment': 'on',
38+
'size': 100
39+
}
40+
]
41+
},
2342
{
2443
'matcherGroup': {
2544
'combiner': 'AND',
@@ -472,17 +491,17 @@ export default function (fetchMock, assert) {
472491
});
473492
});
474493

475-
assert.test(t => { // Testing when we start with preloaded data and MEMORY storage type (is ready from cache immediately)
494+
assert.test(t => { // Testing when we start with initial rollout plan data and MEMORY storage type (is ready from cache immediately)
476495
const testUrls = {
477-
sdk: 'https://sdk.baseurl/readyFromCacheWithPreloadedData',
478-
events: 'https://events.baseurl/readyFromCacheWithPreloadedData'
496+
sdk: 'https://sdk.baseurl/readyFromCacheWithInitialRolloutPlan',
497+
events: 'https://events.baseurl/readyFromCacheWithInitialRolloutPlan'
479498
};
480499

481500
t.plan(5);
482501

483502
fetchMock.getOnce(testUrls.sdk + '/splitChanges?s=1.3&since=25&rbSince=-1', { status: 200, body: { ff: { ...splitChangesMock1.ff, s: 25 } } });
484503
fetchMock.getOnce(testUrls.sdk + '/memberships/nicolas%40split.io', { status: 200, body: membershipsNicolas });
485-
fetchMock.getOnce(testUrls.sdk + '/memberships/nicolas2%40split.io', { status: 200, body: { 'ms': {} } });
504+
fetchMock.getOnce(testUrls.sdk + '/memberships/emi%40split.io', { status: 200, body: { 'ms': {} } });
486505

487506
fetchMock.postOnce(testUrls.events + '/testImpressions/bulk', 200);
488507
fetchMock.postOnce(testUrls.events + '/testImpressions/count', 200);
@@ -493,19 +512,26 @@ export default function (fetchMock, assert) {
493512
type: 'MEMORY',
494513
},
495514
urls: testUrls,
496-
preloadedData: {
497-
since: 25,
498-
flags: [JSON.parse(alwaysOnSplitInverted)]
515+
initialRolloutPlan: {
516+
splitChanges: {
517+
ff: {
518+
t: 25,
519+
d: [JSON.parse(alwaysOnSplitInverted)]
520+
}
521+
},
522+
memberships: {
523+
'[email protected]': { ms: { k: [{ n: 'employees' }] } }
524+
}
499525
}
500526
});
501527

502528
const client = splitio.client();
503-
const client2 = splitio.client('nicolas2@split.io');
529+
const client2 = splitio.client('emi@split.io');
504530

505531
t.equal(client.__getStatus().isReadyFromCache, true, 'Client is ready from cache');
506532

507-
t.equal(client.getTreatment('always_on'), 'off', 'It should evaluate treatments with data from cache instead of control due to Input Validation');
508-
t.equal(client2.getTreatment('always_on'), 'off', 'It should evaluate treatments with data from cache instead of control due to Input Validation');
533+
t.equal(client.getTreatment('always_on'), 'off', 'It should evaluate treatments with data from cache. Key without memberships');
534+
t.equal(client2.getTreatment('always_on'), 'on', 'It should evaluate treatments with data from cache. Key with memberships');
509535

510536
client.on(client.Event.SDK_READY_TIMED_OUT, () => {
511537
t.fail('It should not timeout in this scenario.');

src/__tests__/nodeSuites/evaluations.spec.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,29 @@ export default async function (config, key, assert) {
281281
getTreatmentsTests(client, i);
282282
getTreatmentsWithConfigTests(client, i);
283283

284-
// getCache method
285-
const serverSideState = splitio.getCache();
286-
assert.equal(serverSideState.since, 1457552620999);
287-
assert.equal(serverSideState.flags.length, splitChangesMock1.ff.d.length);
288-
assert.deepEqual(serverSideState.segments, { employees: [], splitters: [], developers: [], segment_excluded_by_rbs: ['[email protected]'] });
289-
assert.deepEqual(serverSideState.memberships, undefined);
290-
const clientSideState = splitio.getCache(['user1']);
291-
assert.equal(clientSideState.since, 1457552620999);
292-
assert.equal(clientSideState.flags.length, splitChangesMock1.ff.d.length);
293-
assert.deepEqual(clientSideState.segments, undefined);
294-
assert.deepEqual(clientSideState.memberships, { user1: { ms: { k: [] }, ls: { k: [] } } });
284+
// getRolloutPlan method
285+
const expectedRolloutPlan = {
286+
splitChanges: splitChangesMock1,
287+
segmentChanges: [
288+
{ name: 'employees', added: [], removed: [], till: 1 },
289+
{ name: 'splitters', added: [], removed: [], till: 1 },
290+
{ name: 'developers', added: [], removed: [], till: 1 },
291+
{ name: 'segment_excluded_by_rbs', added: ['[email protected]'], removed: [], till: 1 }
292+
],
293+
memberships: { '[email protected]': { ms: { k: [{ n: 'segment_excluded_by_rbs' }] }, ls: { k: [] } } }
294+
};
295+
296+
const rolloutPlan = splitio.getRolloutPlan();
297+
assert.deepEqual(rolloutPlan, { ...expectedRolloutPlan, segmentChanges: undefined, memberships: undefined });
298+
299+
const rolloutPlanWithMemberships = splitio.getRolloutPlan({ keys: ['[email protected]'] });
300+
assert.deepEqual(rolloutPlanWithMemberships, { ...expectedRolloutPlan, segmentChanges: undefined });
301+
302+
const rolloutPlanWithSegments = splitio.getRolloutPlan({ exposeSegments: true });
303+
assert.deepEqual(rolloutPlanWithSegments, { ...expectedRolloutPlan, memberships: undefined });
304+
305+
const rolloutPlanWithMembershipsAndSegments = splitio.getRolloutPlan({ keys: [{ matchingKey: '[email protected]', bucketingKey: 'bucketingKey' }], exposeSegments: true });
306+
assert.deepEqual(rolloutPlanWithMembershipsAndSegments, expectedRolloutPlan);
295307

296308
await client.destroy();
297309

src/factory/node.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { pushManagerFactory } from '@splitsoftware/splitio-commons/src/sync/stre
44
import { pollingManagerSSFactory } from '@splitsoftware/splitio-commons/src/sync/polling/pollingManagerSS';
55
import { InRedisStorage } from '@splitsoftware/splitio-commons/src/storages/inRedis';
66
import { InMemoryStorageFactory } from '@splitsoftware/splitio-commons/src/storages/inMemory/InMemoryStorage';
7-
import { getCache } from '@splitsoftware/splitio-commons/src/storages/dataLoader';
7+
import { getRolloutPlan } from '@splitsoftware/splitio-commons/src/storages/dataLoader';
88
import { sdkManagerFactory } from '@splitsoftware/splitio-commons/src/sdkManager';
99
import { sdkClientMethodFactory } from '@splitsoftware/splitio-commons/src/sdkClient/sdkClientMethod';
1010
import { impressionObserverSSFactory } from '@splitsoftware/splitio-commons/src/trackers/impressionObserver/impressionObserverSS';
@@ -54,8 +54,8 @@ function getModules(settings) {
5454
extraProps: (params) => {
5555
if (params.settings.mode !== CONSUMER_MODE) {
5656
return {
57-
getCache(userKeys) {
58-
return getCache(params.settings.log, params.storage, userKeys);
57+
getRolloutPlan(userKeys) {
58+
return getRolloutPlan(params.settings.log, params.storage, userKeys);
5959
}
6060
};
6161
}

ts-tests/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,3 +687,8 @@ let fullAsyncSettings: SplitIO.INodeAsyncSettings = {
687687
fullBrowserSettings.debug = 'ERROR';
688688
fullNodeSettings.debug = 'WARN';
689689
fullAsyncSettings.debug = 'INFO';
690+
691+
// Preload rollout plan
692+
let rolloutPlanSnapshot: SplitIO.RolloutPlan = SDK.getRolloutPlan();
693+
rolloutPlanSnapshot = SDK.getRolloutPlan({ keys: ['key1', { matchingKey: 'key2', bucketingKey: 'bucketingKey' }], exposeSegments: true });
694+
browserSettings.initialRolloutPlan = rolloutPlanSnapshot;

0 commit comments

Comments
 (0)