Skip to content

Commit 44ea95c

Browse files
Merge pull request #869 from splitio/prerequisites
[Prerequisites] Add tests
2 parents 8845f70 + 9367b2f commit 44ea95c

20 files changed

+187
-112
lines changed

.github/workflows/ci-cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") npm run build
5858

5959
- name: Store assets
60-
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/rb_segments_baseline' || github.ref == 'refs/heads/master') }}
60+
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/master') }}
6161
uses: actions/upload-artifact@v4
6262
with:
6363
name: assets
@@ -68,7 +68,7 @@ jobs:
6868
name: Upload assets
6969
runs-on: ubuntu-latest
7070
needs: build
71-
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/rb_segments_baseline' }}
71+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }}
7272
strategy:
7373
matrix:
7474
environment:

CHANGES.txt

Lines changed: 73 additions & 67 deletions
Large diffs are not rendered by default.

karma/config.debug.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
const merge = require('lodash/merge');
44

55
module.exports = merge({}, require('./config'), {
6+
customLaunchers: {
7+
ChromeNoSandbox: {
8+
base: 'Chrome',
9+
flags: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu']
10+
}
11+
},
612
browsers: [
7-
'Chrome'
13+
'ChromeNoSandbox'
814
],
915
webpack: {
1016
mode: 'development'

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio",
3-
"version": "11.2.1-rc.4",
3+
"version": "11.4.0",
44
"description": "Split SDK",
55
"files": [
66
"README.md",
@@ -38,7 +38,7 @@
3838
"node": ">=14.0.0"
3939
},
4040
"dependencies": {
41-
"@splitsoftware/splitio-commons": "2.2.1-rc.5",
41+
"@splitsoftware/splitio-commons": "2.4.0",
4242
"bloom-filters": "^3.0.4",
4343
"ioredis": "^4.28.0",
4444
"js-yaml": "^3.13.1",

src/__tests__/browserSuites/evaluations.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export default function (config, fetchMock, assert) {
362362

363363
};
364364

365-
const evaluationsWithRuleBasedSegments = async (splitio) => {
365+
const evaluationsWithRuleBasedSegmentsAndPrerequisites = async (splitio) => {
366366
fetchMock.getOnce('https://sdk.split.io/api/memberships/emi%40split.io', { status: 200, body: { ms: { k: [{ n: 'segment_excluded_by_rbs' }] } } });
367367
fetchMock.getOnce('https://sdk.split.io/api/memberships/mauro%40split.io', { status: 200, body: { ms: {} } });
368368
fetchMock.getOnce('https://sdk.split.io/api/memberships/bilal%40split.io', { status: 200, body: { ms: {} } });
@@ -372,24 +372,28 @@ export default function (config, fetchMock, assert) {
372372
await client1.ready();
373373
assert.equal(client1.getTreatment('rbs_test_flag'), 'v2', 'key in excluded segment');
374374
assert.equal(client1.getTreatment('rbs_test_flag_negated'), 'v1', 'key in excluded segment');
375+
assert.equal(client1.getTreatment('always_on_if_prerequisite'), 'off', 'prerequisite not satisfied (key in excluded segment)');
375376
await client1.destroy();
376377

377378
const client2 = splitio.client('mauro@split.io');
378379
await client2.ready();
379380
assert.equal(client2.getTreatment('rbs_test_flag'), 'v2', 'excluded key');
380381
assert.equal(client2.getTreatment('rbs_test_flag_negated'), 'v1', 'excluded key');
382+
assert.equal(client2.getTreatment('always_on_if_prerequisite'), 'off', 'prerequisite not satisfied (excluded key)');
381383
await client2.destroy();
382384

383385
const client3 = splitio.client('bilal@split.io');
384386
await client3.ready();
385387
assert.equal(client3.getTreatment('rbs_test_flag'), 'v1', 'key satisfies the rbs condition');
386388
assert.equal(client3.getTreatment('rbs_test_flag_negated'), 'v2', 'key satisfies the rbs condition');
389+
assert.equal(client3.getTreatment('always_on_if_prerequisite'), 'on', 'prerequisite satisfied (key satisfies the rbs condition)');
387390
await client3.destroy();
388391

389392
const client4 = splitio.client('other_key');
390393
await client4.ready();
391394
assert.equal(client4.getTreatment('rbs_test_flag'), 'v2', 'key not in segment');
392395
assert.equal(client4.getTreatment('rbs_test_flag_negated'), 'v1', 'key not in segment');
396+
assert.equal(client4.getTreatment('always_on_if_prerequisite'), 'off', 'prerequisite not satisfied (key not in segment)');
393397
await client4.destroy();
394398
};
395399

@@ -408,7 +412,7 @@ export default function (config, fetchMock, assert) {
408412
getTreatmentsWithConfigTests(client);
409413
getTreatmentsWithInMemoryAttributes(client);
410414

411-
evaluationsWithRuleBasedSegments(splitio).then(() => {
415+
evaluationsWithRuleBasedSegmentsAndPrerequisites(splitio).then(() => {
412416
clientTABucket1.destroy();
413417
client.destroy();
414418
tested++;

src/__tests__/browserSuites/manager.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export default async function (settings, fetchMock, assert) {
4242
'configs': mockSplits.ff.d[index].configurations || {},
4343
'sets': mockSplits.ff.d[index].sets || [],
4444
'defaultTreatment': mockSplits.ff.d[index].defaultTreatment,
45-
'impressionsDisabled': false
45+
'impressionsDisabled': false,
46+
'prerequisites': []
4647
});
4748

4849
assert.equal(manager.split('non_existent'), null, 'Trying to get a manager.split() of a Split that does not exist returns null.');

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ export default function (fetchMock, assert) {
818818
});
819819

820820
await client.ready();
821-
t.equal(manager.names().sort().length, 35, 'active splits should be present for evaluation');
821+
t.equal(manager.names().sort().length, 36, 'active splits should be present for evaluation');
822822

823823
await splitio.destroy();
824824
t.equal(localStorage.getItem('readyFromCache_10.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
@@ -835,7 +835,7 @@ export default function (fetchMock, assert) {
835835

836836
await new Promise(res => client.once(client.Event.SDK_READY_FROM_CACHE, res));
837837

838-
t.equal(manager.names().sort().length, 35, 'active splits should be present for evaluation');
838+
t.equal(manager.names().sort().length, 36, 'active splits should be present for evaluation');
839839
t.false(console.log.calledWithMatch('clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache'), 'It should log a message about cleaning up cache');
840840

841841
await splitio.destroy();
@@ -856,7 +856,7 @@ export default function (fetchMock, assert) {
856856

857857
await new Promise(res => client.once(client.Event.SDK_READY, res));
858858

859-
t.equal(manager.names().sort().length, 35, 'active splits should be present for evaluation');
859+
t.equal(manager.names().sort().length, 36, 'active splits should be present for evaluation');
860860
t.true(console.log.calledWithMatch('clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache'), 'It should log a message about cleaning up cache');
861861

862862
await splitio.destroy();

src/__tests__/browserSuites/telemetry.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default async function telemetryBrowserSuite(fetchMock, t) {
7676

7777
// @TODO check if iDe value is correct
7878
assert.deepEqual(data, {
79-
mE: {}, hE: { sp: { 500: 1 }, ms: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 35, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
79+
mE: {}, hE: { sp: { 500: 1 }, ms: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 36, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
8080
}, 'metrics/usage JSON payload should be the expected');
8181

8282
finish.next();
@@ -96,7 +96,7 @@ export default async function telemetryBrowserSuite(fetchMock, t) {
9696
// @TODO check if iDe value is correct
9797
assert.deepEqual(data, {
9898
mL: {}, mE: {}, hE: {}, hL: {}, // errors and latencies were popped
99-
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 35, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
99+
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 36, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
100100
}, '2nd metrics/usage JSON payload should be the expected');
101101
return 200;
102102
});

src/__tests__/consumer/node_redis.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const expectedImpressionCount = [
6161
];
6262

6363
const expectedSplitName = 'hierarchical_splits_testing_on';
64-
const expectedSplitView = { name: 'hierarchical_splits_testing_on', trafficType: 'user', killed: false, changeNumber: 1487277320548, treatments: ['on', 'off'], configs: {}, sets: [], defaultTreatment: 'off', impressionsDisabled: false };
64+
const expectedSplitView = { name: 'hierarchical_splits_testing_on', trafficType: 'user', killed: false, changeNumber: 1487277320548, treatments: ['on', 'off'], configs: {}, sets: [], defaultTreatment: 'off', impressionsDisabled: false, prerequisites: [] };
6565

6666
const MOCKS = {
6767
'': 'redis-commands',

src/__tests__/mocks/splitchanges.since.-1.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,54 @@
17381738
"configurations": {},
17391739
"sets": [],
17401740
"impressionsDisabled": false
1741+
},
1742+
{
1743+
"orgId": null,
1744+
"environment": null,
1745+
"trafficTypeId": null,
1746+
"trafficTypeName": null,
1747+
"name": "always_on_if_prerequisite",
1748+
"trafficAllocation": 100,
1749+
"trafficAllocationSeed": 1828377380,
1750+
"seed": -790401604,
1751+
"status": "ACTIVE",
1752+
"killed": false,
1753+
"defaultTreatment": "off",
1754+
"prerequisites": [
1755+
{
1756+
"n": "rbs_test_flag",
1757+
"ts": [
1758+
"v1"
1759+
]
1760+
}
1761+
],
1762+
"conditions": [
1763+
{
1764+
"matcherGroup": {
1765+
"combiner": "AND",
1766+
"matchers": [
1767+
{
1768+
"keySelector": {
1769+
"trafficType": "user",
1770+
"attribute": null
1771+
},
1772+
"matcherType": "ALL_KEYS",
1773+
"negate": false,
1774+
"userDefinedSegmentMatcherData": null,
1775+
"whitelistMatcherData": null,
1776+
"unaryNumericMatcherData": null,
1777+
"betweenMatcherData": null
1778+
}
1779+
]
1780+
},
1781+
"partitions": [
1782+
{
1783+
"treatment": "on",
1784+
"size": 100
1785+
}
1786+
]
1787+
}
1788+
]
17411789
}
17421790
],
17431791
"s": -1,

src/__tests__/nodeSuites/evaluations.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ export default async function (config, key, assert) {
175175
assert.equal(client.getTreatment('mauro@split.io', 'rbs_test_flag_negated'), 'v1', 'excluded key');
176176
assert.equal(client.getTreatment('bilal@split.io', 'rbs_test_flag_negated'), 'v2', 'key satisfies the rbs condition');
177177
assert.equal(client.getTreatment('other_key', 'rbs_test_flag_negated'), 'v1', 'key not in segment');
178+
179+
// Prerequisites
180+
assert.equal(client.getTreatment('bilal@split.io', 'always_on_if_prerequisite'), 'on', 'prerequisite satisfied (key satisfies the rbs condition)');
181+
assert.equal(client.getTreatment('emi@split.io', 'always_on_if_prerequisite'), 'off', 'prerequisite not satisfied (key in excluded segment)');
178182
};
179183

180184
const getTreatmentsTests = (client, sdkInstance) => {

src/__tests__/nodeSuites/manager.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export default async function (settings, fetchMock, assert) {
4141
'configs': mockSplits.ff.d[index].configurations || {},
4242
'sets': mockSplits.ff.d[index].sets || [],
4343
'defaultTreatment': mockSplits.ff.d[index].defaultTreatment,
44-
'impressionsDisabled': false
44+
'impressionsDisabled': false,
45+
'prerequisites': []
4546
});
4647

4748
assert.equal(manager.split('non_existent'), null, 'Trying to get a manager.split() of a Split that does not exist returns null.');

src/__tests__/nodeSuites/telemetry.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default async function telemetryNodejsSuite(key, fetchMock, assert) {
6666

6767
// @TODO check if iDe value is correct
6868
assert.deepEqual(data, {
69-
mE: {}, hE: { sp: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 35, seC: 4, skC: 4, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
69+
mE: {}, hE: { sp: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 36, seC: 4, skC: 4, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
7070
}, 'metrics/usage JSON payload should be the expected');
7171

7272
finish.next();
@@ -85,7 +85,7 @@ export default async function telemetryNodejsSuite(key, fetchMock, assert) {
8585
// @TODO check if iDe value is correct
8686
assert.deepEqual(data, {
8787
mL: {}, mE: {}, hE: {}, hL: {}, // errors and latencies were popped
88-
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 35, seC: 4, skC: 4, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
88+
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 36, seC: 4, skC: 4, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
8989
}, '2nd metrics/usage JSON payload should be the expected');
9090
return 200;
9191
});

src/__tests__/offline/browser.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ tape('Browser offline mode', function (assert) {
168168

169169
// Manager tests
170170
const expectedSplitView1 = {
171-
name: 'testing_split', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['on'], configs: {}, defaultTreatment: 'control', sets: [], impressionsDisabled: false
171+
name: 'testing_split', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['on'], configs: {}, defaultTreatment: 'control', sets: [], impressionsDisabled: false, prerequisites: []
172172
};
173173
const expectedSplitView2 = {
174-
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['off'], configs: { off: '{ "color": "blue" }' }, defaultTreatment: 'control', sets: [], impressionsDisabled: false
174+
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['off'], configs: { off: '{ "color": "blue" }' }, defaultTreatment: 'control', sets: [], impressionsDisabled: false, prerequisites: []
175175
};
176176
assert.deepEqual(manager.names(), ['testing_split', 'testing_split_with_config']);
177177
assert.deepEqual(manager.split('testing_split'), expectedSplitView1);
@@ -282,7 +282,7 @@ tape('Browser offline mode', function (assert) {
282282

283283
// Manager tests
284284
const expectedSplitView3 = {
285-
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['nope'], configs: {}, defaultTreatment: 'control', sets: [], impressionsDisabled: false
285+
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['nope'], configs: {}, defaultTreatment: 'control', sets: [], impressionsDisabled: false, prerequisites: []
286286
};
287287
assert.deepEqual(manager.names(), ['testing_split', 'testing_split_2', 'testing_split_3', 'testing_split_with_config']);
288288
assert.deepEqual(manager.split('testing_split'), expectedSplitView1);

0 commit comments

Comments
 (0)