Skip to content

Commit 5c9c743

Browse files
Filter segments by type when parsing split and RBS definitions
1 parent 688a8ff commit 5c9c743

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/sync/polling/updaters/__tests__/splitChangesUpdater.spec.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { telemetryTrackerFactory } from '../../../../trackers/telemetryTracker';
1414
import { splitNotifications } from '../../../streaming/__tests__/dataMocks';
1515
import { RBSegmentsCacheInMemory } from '../../../../storages/inMemory/RBSegmentsCacheInMemory';
1616
import { RB_SEGMENT_UPDATE, SPLIT_UPDATE } from '../../../streaming/constants';
17+
import { IN_RULE_BASED_SEGMENT } from '../../../../utils/constants';
1718

1819
const ARCHIVED_FF = 'ARCHIVED';
1920

@@ -84,13 +85,31 @@ const testFFEmptySet: ISplit =
8485
conditions: [],
8586
sets: []
8687
};
88+
// @ts-ignore
89+
const rbsWithExcludedSegment: IRBSegment = {
90+
name: 'rbs',
91+
status: 'ACTIVE',
92+
conditions: [],
93+
excluded: {
94+
segments: [{
95+
type: 'standard',
96+
name: 'C'
97+
}, {
98+
type: 'rule-based',
99+
name: 'D'
100+
}]
101+
}
102+
};
87103

88104
test('splitChangesUpdater / segments parser', () => {
105+
let segments = parseSegments(activeSplitWithSegments as ISplit);
106+
expect(segments).toEqual(new Set(['A', 'B']));
89107

90-
const segments = parseSegments(activeSplitWithSegments as ISplit);
108+
segments = parseSegments(rbsWithExcludedSegment);
109+
expect(segments).toEqual(new Set(['C']));
91110

92-
expect(segments.has('A')).toBe(true);
93-
expect(segments.has('B')).toBe(true);
111+
segments = parseSegments(rbsWithExcludedSegment, IN_RULE_BASED_SEGMENT);
112+
expect(segments).toEqual(new Set(['D']));
94113
});
95114

96115
test('splitChangesUpdater / compute splits mutation', () => {

src/sync/polling/updaters/splitChangesUpdater.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ function checkAllSegmentsExist(segments: ISegmentsCacheBase): Promise<boolean> {
2626
}
2727

2828
/**
29-
* Collect segments from a raw split definition.
29+
* Collect segments from a raw FF or RBS definition.
3030
* Exported for testing purposes.
3131
*/
3232
export function parseSegments(ruleEntity: ISplit | IRBSegment, matcherType: typeof IN_SEGMENT | typeof IN_RULE_BASED_SEGMENT = IN_SEGMENT): Set<string> {
3333
const { conditions = [], excluded } = ruleEntity as IRBSegment;
3434

35-
const segments = new Set<string>(
36-
excluded && excluded.segments ? excluded.segments.map(segment => segment.name) : []
37-
);
35+
const segments = new Set<string>();
36+
if (excluded && excluded.segments) {
37+
excluded.segments.forEach(({ type, name }) => {
38+
if ((type === 'standard' && matcherType === IN_SEGMENT) || (type === 'rule-based' && matcherType === IN_RULE_BASED_SEGMENT)) {
39+
segments.add(name);
40+
}
41+
});
42+
}
3843

3944
for (let i = 0; i < conditions.length; i++) {
4045
const matchers = conditions[i].matcherGroup.matchers;

0 commit comments

Comments
 (0)