Skip to content

fix: When rollout has no rule, should return null #235

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 4 commits into from
Jul 14, 2020
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
18 changes: 18 additions & 0 deletions OptimizelySDK.Tests/DecisionServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,24 @@ public void TestGetVariationForFeatureExperimentGivenMutexGroupAndUserNotBuckete
#region GetVariationForFeatureRollout Tests

// Should return null when rollout doesn't exist for the feature.
[Test]
public void TestGetVariationForFeatureRolloutWhenNoRuleInRollouts()
{
var projectConfig = DatafileProjectConfig.Create(TestData.EmptyRolloutDatafile, new NoOpLogger(), new NoOpErrorHandler());

Assert.IsNotNull(projectConfig);
var featureFlag = projectConfig.FeatureKeyMap["empty_rollout"];
var rollout = projectConfig.GetRolloutFromId(featureFlag.RolloutId);

Assert.AreEqual(rollout.Experiments.Count, 0);

var decisionService = new DecisionService(new Bucketer(new NoOpLogger()), new NoOpErrorHandler(), null, new NoOpLogger());

var variation = decisionService.GetVariationForFeatureRollout(featureFlag, "userId1", null, projectConfig);

Assert.IsNull(variation);
}

[Test]
public void TestGetVariationForFeatureRolloutWhenRolloutIsNotInDataFile()
{
Expand Down
44 changes: 44 additions & 0 deletions OptimizelySDK.Tests/EmptyRolloutRule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"version": "4",
"rollouts": [
{
"experiments": [
],
"id": "18309384009"
}
],
"typedAudiences": [],
"anonymizeIP": true,
"projectId": "18326250003",
"variables": [],
"featureFlags": [
{
"experimentIds": [],
"rolloutId": "18309384009",
"variables": [
{
"defaultValue": "",
"type": "string",
"id": "18323951833",
"key": "var_1"
}
],
"id": "18244658520",
"key": "empty_rollout"
}
],
"experiments": [],
"audiences": [
{
"conditions": "[\"or\", {\"match\": \"exact\", \"name\": \"$opt_dummy_attribute\", \"type\": \"custom_attribute\", \"value\": \"$opt_dummy_value\"}]",
"id": "$opt_dummy_audience",
"name": "Optimizely-Generated Audience for Backwards Compatibility"
}
],
"groups": [],
"attributes": [],
"botFiltering": false,
"accountId": "8272261422",
"events": [],
"revision": "2"
}
1 change: 1 addition & 0 deletions OptimizelySDK.Tests/OptimizelySDK.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<ItemGroup>
<EmbeddedResource Include="TestData.json" />
<EmbeddedResource Include="simple_ab_experiments.json" />
<EmbeddedResource Include="EmptyRolloutRule.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OptimizelySDK\OptimizelySDK.csproj">
Expand Down
7 changes: 7 additions & 0 deletions OptimizelySDK.Tests/Utils/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TestData
private static string simpleABExperimentsDatafile = null;
private static string unsupportedVersionDatafile = null;
private static string typedAudienceDatafile = null;
private static string emptyRolloutDatafile = null;

public static string Datafile
{
Expand All @@ -52,6 +53,12 @@ public static string UnsupportedVersionDatafile
}
}

public static string EmptyRolloutDatafile {
get {
return emptyRolloutDatafile ?? (emptyRolloutDatafile = LoadJsonData("EmptyRolloutRule.json"));
}
}

public static string TypedAudienceDatafile
{
get
Expand Down
4 changes: 4 additions & 0 deletions OptimizelySDK/Bucketing/DecisionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ public virtual FeatureDecision GetVariationForFeatureRollout(FeatureFlag feature
return null;
}

if (rollout.Experiments == null || rollout.Experiments.Count == 0) {
return null;
}

Variation variation = null;
var rolloutRulesLength = rollout.Experiments.Count;

Expand Down