Skip to content

Commit da3ecc0

Browse files
Rename split to definition in logs and declarations to generalize the concept for Configs support
1 parent aabd919 commit da3ecc0

17 files changed

Lines changed: 91 additions & 91 deletions

src/evaluator/__tests__/evaluate-feature.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { evaluateFeature } from '../index';
2-
import { EXCEPTION, NOT_IN_SPLIT, SPLIT_ARCHIVED, SPLIT_KILLED, SPLIT_NOT_FOUND } from '../../utils/labels';
2+
import { EXCEPTION, NOT_IN_SPLIT, SPLIT_ARCHIVED, SPLIT_KILLED, DEFINITION_NOT_FOUND } from '../../utils/labels';
33
import { loggerMock } from '../../logger/__tests__/sdkLogger.mock';
44
import { ISplit } from '../../dtos/types';
55
import { IStorageSync } from '../../storages/types';
@@ -53,7 +53,7 @@ test('EVALUATOR / should return right label, treatment and config if storage ret
5353
config: '{color:\'black\'}', changeNumber: 1487277320548
5454
};
5555
const expectedOutputControl = {
56-
treatment: 'control', label: SPLIT_NOT_FOUND, config: null
56+
treatment: 'control', label: DEFINITION_NOT_FOUND, config: null
5757
};
5858

5959
const evaluationWithConfig = evaluateFeature(

src/evaluator/__tests__/evaluate-features.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { evaluateFeatures, evaluateFeaturesByFlagSets } from '../index';
2-
import { EXCEPTION, NOT_IN_SPLIT, SPLIT_ARCHIVED, SPLIT_KILLED, SPLIT_NOT_FOUND } from '../../utils/labels';
2+
import { EXCEPTION, NOT_IN_SPLIT, SPLIT_ARCHIVED, SPLIT_KILLED, DEFINITION_NOT_FOUND } from '../../utils/labels';
33
import { loggerMock } from '../../logger/__tests__/sdkLogger.mock';
44
import { WARN_FLAGSET_WITHOUT_FLAGS } from '../../logger/constants';
55
import { ISplit } from '../../dtos/types';
@@ -71,7 +71,7 @@ test('EVALUATOR - Multiple evaluations at once / should return right labels, tre
7171
config: '{color:\'black\'}', changeNumber: 1487277320548
7272
},
7373
not_existent_split: {
74-
treatment: 'control', label: SPLIT_NOT_FOUND, config: null
74+
treatment: 'control', label: DEFINITION_NOT_FOUND, config: null
7575
},
7676
};
7777

@@ -122,7 +122,7 @@ describe('EVALUATOR - Multiple evaluations at once by flag sets', () => {
122122
config: '{color:\'black\'}', changeNumber: 1487277320548
123123
},
124124
not_existent_split: {
125-
treatment: 'control', label: SPLIT_NOT_FOUND, config: null
125+
treatment: 'control', label: DEFINITION_NOT_FOUND, config: null
126126
},
127127
};
128128

src/evaluator/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { engineParser } from './Engine';
22
import { thenable } from '../utils/promise/thenable';
3-
import { EXCEPTION, SPLIT_NOT_FOUND } from '../utils/labels';
3+
import { EXCEPTION, DEFINITION_NOT_FOUND } from '../utils/labels';
44
import { CONTROL } from '../utils/constants';
55
import { ISplit, MaybeThenable } from '../dtos/types';
66
import { IStorageAsync, IStorageSync } from '../storages/types';
@@ -148,7 +148,7 @@ function getEvaluation(
148148
): MaybeThenable<IEvaluationResult> {
149149
let evaluation: MaybeThenable<IEvaluationResult> = {
150150
treatment: CONTROL,
151-
label: SPLIT_NOT_FOUND,
151+
label: DEFINITION_NOT_FOUND,
152152
config: null
153153
};
154154

src/logger/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const WARN_SETTING_NULL = 211;
7171
export const WARN_TRIMMING_PROPERTIES = 212;
7272
export const WARN_CONVERTING = 213;
7373
export const WARN_TRIMMING = 214;
74-
export const WARN_NOT_EXISTENT_SPLIT = 215;
74+
export const WARN_NOT_EXISTENT_DEFINITION = 215;
7575
export const WARN_LOWERCASE_TRAFFIC_TYPE = 216;
7676
export const WARN_NOT_EXISTENT_TT = 217;
7777
export const WARN_INTEGRATION_INVALID = 218;

src/logger/messages/warn.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ export const codesWarn: [number, string][] = codesError.concat([
1414
[c.SUBMITTERS_PUSH_FAILS, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Dropping %s after retry. Reason: %s.'],
1515
[c.SUBMITTERS_PUSH_RETRY, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Failed to push %s, keeping data to retry on next iteration. Reason: %s.'],
1616
// client status
17-
[c.CLIENT_NOT_READY_FROM_CACHE, '%s: the SDK is not ready to evaluate. Results may be incorrect%s. Make sure to wait for SDK readiness before using this method.'],
17+
[c.CLIENT_NOT_READY_FROM_CACHE, '%s: the SDK is not ready to evaluate. Results may be incorrect. Make sure to wait for SDK readiness before using this method.'],
1818
[c.CLIENT_NO_LISTENER, 'No listeners for SDK_READY event detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet synchronized with the backend.'],
1919
// input validation
2020
[c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],
2121
[c.WARN_TRIMMING_PROPERTIES, '%s: more than 300 properties were provided. Some of them will be trimmed when processed.'],
2222
[c.WARN_CONVERTING, '%s: %s "%s" is not of type string, converting.'],
2323
[c.WARN_TRIMMING, '%s: %s "%s" has extra whitespace, trimming.'],
24-
[c.WARN_NOT_EXISTENT_SPLIT, '%s: feature flag "%s" does not exist in this environment. Please double check what feature flags exist in the Split user interface.'],
24+
[c.WARN_NOT_EXISTENT_DEFINITION, '%s: definition "%s" does not exist in this environment. Please double check what definitions exist in the Split user interface.'],
2525
[c.WARN_LOWERCASE_TRAFFIC_TYPE, '%s: traffic_type_name should be all lowercase - converting string to lowercase.'],
2626
[c.WARN_NOT_EXISTENT_TT, '%s: traffic type "%s" does not have any corresponding feature flag in this environment, make sure you\'re tracking your events to a valid traffic type defined in the Split user interface.'],
2727
[c.WARN_FLAGSET_NOT_CONFIGURED, '%s: you passed %s which is not part of the configured FlagSetsFilter, ignoring Flag Set.'],

src/sdkClient/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { evaluateFeature, evaluateFeatures, evaluateFeaturesByFlagSets } from '../evaluator';
22
import { thenable } from '../utils/promise/thenable';
33
import { getMatching, getBucketing } from '../utils/key';
4-
import { validateSplitExistence } from '../utils/inputValidation/splitExistence';
4+
import { validateDefinitionExistence } from '../utils/inputValidation/definitionExistence';
55
import { validateTrafficTypeExistence } from '../utils/inputValidation/trafficTypeExistence';
66
import { SDK_NOT_READY } from '../utils/labels';
77
import { CONTROL, TREATMENT, TREATMENTS, TREATMENT_WITH_CONFIG, TREATMENTS_WITH_CONFIG, TRACK, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, TREATMENTS_BY_FLAGSETS, TREATMENTS_BY_FLAGSET, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENT_WITH_CONFIG, GET_TREATMENT, GET_TREATMENTS, TRACK_FN_LABEL } from '../utils/constants';
@@ -151,7 +151,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
151151
}
152152

153153
// If no target/key, no impression is tracked
154-
if (key && validateSplitExistence(log, readinessManager, featureFlagName, label, invokingMethodName)) {
154+
if (key && validateDefinitionExistence(log, readinessManager, featureFlagName, label, invokingMethodName)) {
155155
const matchingKey = getMatching(key);
156156
const bucketingKey = getBucketing(key);
157157

src/sdkClient/clientInputValidation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
4646
const isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
4747
const options = validateEvaluationOptions(log, maybeOptions, methodName);
4848

49-
validateIfReadyFromCache(log, readinessManager, methodName, nameOrNames);
49+
validateIfReadyFromCache(log, readinessManager, methodName);
5050

5151
const valid = isNotDestroyed && key && nameOrNames && attributes !== false;
5252

src/sdkManager/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { objectAssign } from '../utils/lang/objectAssign';
22
import { thenable } from '../utils/promise/thenable';
33
import { find } from '../utils/lang';
4-
import { validateSplit, validateSplitExistence, validateIfOperational } from '../utils/inputValidation';
4+
import { validateSplit, validateDefinitionExistence, validateIfOperational } from '../utils/inputValidation';
55
import { ISplitsCacheAsync, ISplitsCacheSync } from '../storages/types';
66
import { ISdkReadinessManager } from '../readiness/types';
77
import { ISplit } from '../dtos/types';
@@ -74,12 +74,12 @@ export function sdkManagerFactory<TSplitCache extends ISplitsCacheSync | ISplits
7474

7575
if (thenable(split)) {
7676
return split.catch(() => null).then(result => { // handle possible rejections when using pluggable storage
77-
validateSplitExistence(log, readinessManager, splitName, result, SPLIT_FN_LABEL);
77+
validateDefinitionExistence(log, readinessManager, splitName, result, SPLIT_FN_LABEL);
7878
return objectToView(result);
7979
});
8080
}
8181

82-
validateSplitExistence(log, readinessManager, splitName, split, SPLIT_FN_LABEL);
82+
validateDefinitionExistence(log, readinessManager, splitName, split, SPLIT_FN_LABEL);
8383

8484
return objectToView(split);
8585
},

src/sync/polling/pollingManagerSS.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function pollingManagerSSFactory(
2424
// Start periodic fetching (polling)
2525
start() {
2626
log.info(POLLING_START);
27-
log.debug(LOG_PREFIX_SYNC_POLLING + `Splits will be refreshed each ${settings.scheduler.featuresRefreshRate} millis`);
27+
log.debug(LOG_PREFIX_SYNC_POLLING + `Definitions will be refreshed each ${settings.scheduler.featuresRefreshRate} millis`);
2828
log.debug(LOG_PREFIX_SYNC_POLLING + `Segments will be refreshed each ${settings.scheduler.segmentsRefreshRate} millis`);
2929

3030
const startingUp = splitsSyncTask.start();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
import * as LabelConstants from '../../labels';
3+
4+
import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock';
5+
6+
import { validateDefinitionExistence } from '../definitionExistence';
7+
import { IReadinessManager } from '../../../readiness/types';
8+
import { WARN_NOT_EXISTENT_DEFINITION } from '../../../logger/constants';
9+
10+
describe('Split existence (special case)', () => {
11+
12+
afterEach(() => { loggerMock.mockClear(); });
13+
14+
test('Should return a boolean indicating if the SDK was ready and there was no Split object or "definition not found" label', () => {
15+
// @ts-expect-error
16+
let readinessManagerMock = {
17+
isReady: jest.fn(() => false) // Fake the signal for the non ready SDK
18+
} as IReadinessManager;
19+
20+
expect(validateDefinitionExistence(loggerMock, readinessManagerMock, 'some_split', {}, 'test_method')).toBe(true); // Should always return true when the SDK is not ready.
21+
expect(validateDefinitionExistence(loggerMock, readinessManagerMock, 'some_split', null, 'test_method')).toBe(true); // Should always return true when the SDK is not ready.
22+
expect(validateDefinitionExistence(loggerMock, readinessManagerMock, 'some_split', undefined, 'test_method')).toBe(true); // Should always return true when the SDK is not ready.
23+
expect(validateDefinitionExistence(loggerMock, readinessManagerMock, 'some_split', 'a label', 'test_method')).toBe(true); // Should always return true when the SDK is not ready.
24+
expect(validateDefinitionExistence(loggerMock, readinessManagerMock, 'some_split', LabelConstants.DEFINITION_NOT_FOUND, 'test_method')).toBe(true); // Should always return true when the SDK is not ready.
25+
26+
expect(loggerMock.warn).not.toBeCalled(); // There should have been no warning logs since the SDK was not ready yet.
27+
expect(loggerMock.error).not.toBeCalled(); // There should have been no error logs since the SDK was not ready yet.
28+
29+
// Prepare the mock to fake that the SDK is ready now.
30+
(readinessManagerMock.isReady as jest.Mock).mockImplementation(() => true);
31+
32+
expect(validateDefinitionExistence(loggerMock, readinessManagerMock, 'other_split', {}, 'other_method')).toBe(true); // Should return true if it receives a Split Object instead of null (when the object is not found, for manager).
33+
expect(validateDefinitionExistence(loggerMock, readinessManagerMock, 'other_split', 'a label', 'other_method')).toBe(true); // Should return true if it receives a Label and it is not split not found (when the Split was not found on the storage, for client).
34+
35+
expect(loggerMock.warn).not.toBeCalled(); // There should have been no warning logs since the values we used so far were considered valid.
36+
expect(loggerMock.error).not.toBeCalled(); // There should have been no error logs since the values we used so far were considered valid.
37+
38+
expect(validateDefinitionExistence(loggerMock, readinessManagerMock, 'other_split', null, 'other_method')).toBe(false); // Should return false if it receives a non-truthy value as a split object or label
39+
expect(validateDefinitionExistence(loggerMock, readinessManagerMock, 'other_split', undefined, 'other_method')).toBe(false); // Should return false if it receives a non-truthy value as a split object or label
40+
expect(validateDefinitionExistence(loggerMock, readinessManagerMock, 'other_split', LabelConstants.DEFINITION_NOT_FOUND, 'other_method')).toBe(false); // Should return false if it receives a label but it is the split not found one.
41+
42+
expect(loggerMock.warn).toBeCalledTimes(3); // It should have logged 3 warnings, one per each time we called it
43+
loggerMock.warn.mock.calls.forEach(call => expect(call).toEqual([WARN_NOT_EXISTENT_DEFINITION, ['other_method', 'other_split']])); // Warning logs should have the correct message.
44+
45+
expect(loggerMock.error).not.toBeCalled(); // We log warnings, not errors.
46+
});
47+
});

0 commit comments

Comments
 (0)