Skip to content

Commit

Permalink
add test to check if flexible rollout handles a null context correctly (
Browse files Browse the repository at this point in the history
#126)

* fix: flexible rollout should work now without a context
  • Loading branch information
sighphyre authored Feb 22, 2023
1 parent 60ac24c commit 28f8a3d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Unleash/Strategies/FlexibleRolloutStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ private string ResolveStickiness(string stickiness, UnleashContext context)
case "random":
return randomGenerator();
case "default":
return context.UserId
?? context.SessionId
return context?.UserId
?? context?.SessionId
?? randomGenerator();
default:
return context.GetByName(stickiness);
Expand Down
18 changes: 18 additions & 0 deletions tests/Unleash.Tests/Strategy/FlexibleRolloutStrategyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,23 @@ public void Should_be_enabled_for_rollout_100_and_custom_stickiness_customField_
// Assert
enabled.Should().BeTrue();
}

[Test]
public void Should_be_enabled_without_a_context() {
// Arrange
var strategy = new FlexibleRolloutStrategy();
var parameters = new Dictionary<string, string>
{
{ "rollout", "100" },
{ "stickiness", "default" },
{ "groupId", "Feature.flexible.rollout.custom.stickiness_100" }
};

// Act
var enabled = strategy.IsEnabled(parameters, null);

// Assert
enabled.Should().BeTrue();
}
}
}

0 comments on commit 28f8a3d

Please sign in to comment.