Skip to content

fix(decision_service): Return null variation if experiment key does not exist in feature's experimentIds array. #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 11, 2019
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
4 changes: 2 additions & 2 deletions packages/optimizely-sdk/lib/core/decision_service/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2017-2018, Optimizely, Inc. and contributors *
* Copyright 2017-2019, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand Down Expand Up @@ -315,7 +315,7 @@ DecisionService.prototype._getVariationForFeatureExperiment = function(feature,
var group = this.configObj.groupIdMap[feature.groupId];
if (group) {
experiment = this._getExperimentInGroup(group, userId);
if (experiment) {
if (experiment && feature.experimentIds.indexOf(experiment.id) !== -1) {
variationKey = this.getVariation(experiment.key, userId, attributes);
}
}
Expand Down
14 changes: 13 additions & 1 deletion packages/optimizely-sdk/lib/core/decision_service/index.tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2017-2018, Optimizely, Inc. and contributors *
* Copyright 2017-2019, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand Down Expand Up @@ -889,6 +889,18 @@ describe('lib/core/decision_service', function() {
assert.deepEqual(decision, expectedDecision);
sinon.assert.calledWithExactly(mockLogger.log, LOG_LEVEL.DEBUG, 'DECISION_SERVICE: User user1 is not in any experiment on the feature feature_with_group.');
});

it('returns null decision for group experiment not referenced by the feature', function() {
var noTrafficExpFeature = configObj.featureKeyMap.feature_exp_no_traffic;
var decision = decisionServiceInstance.getVariationForFeature(noTrafficExpFeature, 'user1');
var expectedDecision = {
experiment: null,
variation: null,
decisionSource: null,
};
assert.deepEqual(decision, expectedDecision);
sinon.assert.calledWithExactly(mockLogger.log, LOG_LEVEL.DEBUG, 'DECISION_SERVICE: User user1 is not in any experiment on the feature feature_exp_no_traffic.');
});
});

describe('user not bucketed into the group', function() {
Expand Down
10 changes: 8 additions & 2 deletions packages/optimizely-sdk/lib/optimizely/index.tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2016-2018, Optimizely, Inc. and contributors *
* Copyright 2016-2019, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand Down Expand Up @@ -2991,7 +2991,7 @@ describe('lib/optimizely', function() {
assert.strictEqual(result.length, 2);
assert.isAbove(result.indexOf('test_feature'), -1);
assert.isAbove(result.indexOf('test_feature_for_experiment'), -1);
sinon.assert.callCount(optlyInstance.isFeatureEnabled, 6);
sinon.assert.callCount(optlyInstance.isFeatureEnabled, 7);
sinon.assert.calledWithExactly(
optlyInstance.isFeatureEnabled,
'test_feature',
Expand Down Expand Up @@ -3028,6 +3028,12 @@ describe('lib/optimizely', function() {
'user1',
attributes
);
sinon.assert.calledWithExactly(
optlyInstance.isFeatureEnabled,
'feature_exp_no_traffic',
'user1',
attributes
);
});
});

Expand Down
92 changes: 91 additions & 1 deletion packages/optimizely-sdk/lib/tests/test_data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016-2018, Optimizely
* Copyright 2016-2019, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -429,6 +429,15 @@ var configWithFeatures = {
'id': '599110',
'experimentIds': [],
'variables': []
},
{
'rolloutId': '',
'key': 'feature_exp_no_traffic',
'id': '4482920079',
'experimentIds': [
'12115595439'
],
'variables': []
}
],
'experiments': [
Expand Down Expand Up @@ -637,6 +646,74 @@ var configWithFeatures = {
'entityId': '599082'
}
]
},
{
'policy': 'random',
'id': '595025',
'experiments': [
{
'trafficAllocation': [
{
'endOfRange': 10000,
'entityId': '12098126627'
}
],
'layerId': '595005',
'forcedVariations': {},
'audienceIds': [],
'variations': [
{
'key': 'all_traffic_variation',
'id': '12098126627',
'variables': []
},
{
'key': 'no_traffic_variation',
'id': '12098126628',
'variables': []
}
],
'status': 'Running',
'key': 'all_traffic_experiment',
'id': '12198292375'
},
{
'trafficAllocation': [
{
'endOfRange': 5000,
'entityId': '12098126629'
},
{
'endOfRange': 10000,
'entityId': '12098126630'
}
],
'layerId': '12187694826',
'forcedVariations': {},
'audienceIds': [],
'variations': [
{
'key': 'variation_5000',
'id': '12098126629',
'variables': []
},
{
'key': 'variation_10000',
'id': '12098126630',
'variables': []
}
],
'status': 'Running',
'key': 'no_traffic_experiment',
'id': '12115595439'
}
],
'trafficAllocation': [
{
'endOfRange': 10000,
'entityId': '12198292375'
}
]
}
],
'attributes': [
Expand Down Expand Up @@ -1333,6 +1410,10 @@ var datafileWithFeaturesExpectedData = {
},
599080: {},
599081: {},
12098126627: {},
12098126628: {},
12098126629: {},
12098126630: {},
},

featureKeyMap: {
Expand Down Expand Up @@ -1547,6 +1628,15 @@ var datafileWithFeaturesExpectedData = {
'variables': [],
variableKeyMap: {},
},
feature_exp_no_traffic: {
'rolloutId': '',
'key': 'feature_exp_no_traffic',
'id': '4482920079',
'experimentIds': ['12115595439'],
'variables': [],
variableKeyMap: {},
groupId: '595025',
},
},
};

Expand Down