-
Notifications
You must be signed in to change notification settings - Fork 37
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
fix: flexible rollout strategy without context #146
fix: flexible rollout strategy without context #146
Conversation
The flexible rollout strategy should evaluate default and random stickiness even if context is not provided.
Pull Request Test Coverage Report for Build 5463576496
💛 - Coveralls |
2b046a0
to
2341bb7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some 2c.
|
||
stickiness = params.fetch('stickiness', 'default') | ||
return false unless context.instance_of?(Unleash::Context) || ['random', 'default'].include?(stickiness) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit complex logic. Any chance to try to extract the check into a private method, and use the method name to document what the check is trying to accomplish?
|
||
stickiness = params.fetch('stickiness', 'default') | ||
return false unless context.instance_of?(Unleash::Context) || ['random', 'default'].include?(stickiness) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return false unless context.instance_of?(Unleash::Context) || ['random', 'default'].include?(stickiness) | |
return false if is_context_invalid?(context, stickiness) |
# Context is always valid when using random or default strategies.
def is_context_invalid?(context, stickiness)
!context.instance_of?(Unleash::Context) || ['random', 'default'].include?(stickiness)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to rename the method, not sure it's the most appropriate. Just a suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it slightly different in order to keep the argument order and be more explicit.
|
||
stickiness = params.fetch('stickiness', 'default') | ||
return false unless context_is_sufficient?(stickiness, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any way we can simplify further by turning the unless
to a if
?
Would a name like context_required?
/context_needed?
/context_valid?
/context_invalid?
be more descriptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i can change it
@@ -32,6 +33,12 @@ def is_enabled?(params = {}, context = nil) | |||
|
|||
private | |||
|
|||
def context_is_sufficient?(stickiness, context) | |||
return true if ['random', 'default'].include?(stickiness) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that it will not evaluate the strategy randomly when the stickiness is set to random
.
You sure that's the desired behaviour?
Maybe it's worth having a rspec test just for the'stickiness' => 'radom'
case? (where a couple of different seeds are hard coded?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will just let it continue to the resolve stickiness like it did before, this is just a safe guard. It returns to the is_enabled method, not to the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but what happens up the stack, in the is_enabled?
method? it returns right away, no? or is the boolean logic a bit hard to read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it only returns false when its supposed to, if the context is sufficient it continues...
} | ||
|
||
expect(strategy.is_enabled?(params, unleash_context)).to be_falsey | ||
expect(strategy.is_enabled?(params, nil)).to be_falsey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that this also passes? (if you deem that necessary)
expect(strategy.is_enabled?(params, nil)).to be_falsey | |
expect(strategy.is_enabled?(params, "invalid_context")).to be_falsey | |
expect(strategy.is_enabled?(params, nil)).to be_falsey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch, i fixed it now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patience. Looks great now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patience. Looks great now!
The flexible rollout strategy should evaluate default and random stickiness even if context is not provided.