Skip to content

Commit

Permalink
fix(client): run set to AllB returns B
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhck committed Jul 11, 2020
1 parent 217f55b commit c645432
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Sdk.Test/FeatureClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public void Setup()
FeatureToken = GetUuid(),
RunId = GetUuid(),
RunToken = GetUuid()
},
new RunningFeature
{
Allocation = 50,
FeatureId = "APP-3",
FeatureToken = GetUuid(),
RunId = GetUuid(),
RunStatus = "AllB",
RunToken = GetUuid()
}
};
var mockWorker = new Mock<IFeatureWorker>();
Expand Down Expand Up @@ -101,5 +110,22 @@ public void TestFeatureWithAllocationHasLowAllocationBias()
Assert.LessOrEqual(biasPerc, 0.5);
Assert.LessOrEqual(biasWithZPerc, 0.5);
}

[Test]
public void TestFeatureWithAllBAlwaysReturnsB()
{
var dictionary = new Dictionary<char, int> {['A'] = 0, ['B'] = 0, ['X'] = 0, ['Z'] = 0};
var client = new FeatureClient(_featureWorker, _userDataRepo);
for (var i = 0; i < 1000000; i++)
{
var variant = client.GetVariant("APP-3");
dictionary[variant] = dictionary[variant] + 1;
}

Assert.AreEqual(0, dictionary['X']);
Assert.AreEqual(0, dictionary['Z']);
Assert.AreEqual(0, dictionary['A']);
Assert.AreEqual(1000000, dictionary['B']);
}
}
}
5 changes: 5 additions & 0 deletions Sdk/FeatureContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public char GetVariant(string featId)
return 'X';
}

if (feature.RunStatus == "AllB")
{
return 'B';
}

if (feature.Allocation.Value == 100 || GetBucket(_userDataRepo.GetUserId(), feature.FeatureToken, 100) <= feature.Allocation)
{
var bucket = GetBucket(_userDataRepo.GetUserId(), feature.RunToken, 2);
Expand Down

0 comments on commit c645432

Please # to comment.