-
Notifications
You must be signed in to change notification settings - Fork 28
feat(ForcedDecisions): add forced-decisions APIs to OptimizelyUserContext #287
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
Conversation
Co-authored-by: yasirfolio3 <[email protected]>
@@ -28,6 +28,7 @@ | |||
let(:spy_user_profile_service) { spy('user_profile_service') } |
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 feel we should have new tests related to forced_decision in this test file as well. Mainly tests related to changes in the decision_service.
@@ -80,4 +83,249 @@ | |||
expect(original_attributes).to eq('browser' => 'firefox') | |||
end | |||
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.
I feel we need the following test scenarios:
- Async behaviour when setting and getting forced decisions.
- Async behaviour when getting and removing forced decisions.
- Checking for forced-decision in the fallback-rule. Similarly, for all cases where
FindValidatedForcedDecision
is used. - Validation for empty rule_key when setting forced decision.
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 overall looks good! Some changes suggested.
return nil if @forced_decisions.empty? | ||
|
||
forced_decision_key = ForcedDecision.new(flag_key, rule_key) | ||
variation_key = @forced_decisions[forced_decision_key] |
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.
Don't we need mutex sync for all forced_decisions accesses (set, get, remove and clone)?
expect(status).to be true | ||
status = user_context_obj.remove_all_forced_decision | ||
expect(status).to be true | ||
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.
can we validate both event and notification for the 3 cases? (flagKey), (flagKey, expRule), (flagKey, delRule)
variations = [] | ||
get_rules_for_flag(flag).each do |rule| | ||
rule['variations'].each do |rule_variation| | ||
variations.push(rule_variation) if variations.select { |variation| variation['id'] == rule_variation['id'] } |
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.
Does this filter out redundant variations. Can we add a test case for flag_variation_map?
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.
variations.select
can return multiple values but we are using if condition just to check if any value exists.
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 may be confused but the logic looks opposite to me. We need to collect all variations used in rules for a flag (see related discussion here - optimizely/php-sdk#233 (comment)).
We need push variations only if NOT exist already.
Consider to extract this building flag-variations map as a separate function and add a test case.
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 see some of the key issues not addressed. Can you take a look at those open comments?
Also clean up deprecation messages from PR summary.
variations = [] | ||
get_rules_for_flag(flag).each do |rule| | ||
rule['variations'].each do |rule_variation| | ||
variations.push(rule_variation) if variations.select { |variation| variation['id'] == rule_variation['id'] } |
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 may be confused but the logic looks opposite to me. We need to collect all variations used in rules for a flag (see related discussion here - optimizely/php-sdk#233 (comment)).
We need push variations only if NOT exist already.
Consider to extract this building flag-variations map as a separate function and add a test case.
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.
LGTM
@@ -947,7 +961,8 @@ def get_feature_variable_for_type(feature_flag_key, variable_key, variable_type, | |||
return nil | |||
end | |||
|
|||
decision, = @decision_service.get_variation_for_feature(config, feature_flag, user_id, attributes) | |||
user_context = create_user_context(user_id, attributes) | |||
decision, = @decision_service.get_variation_for_feature(config, feature_flag, user_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.
why there is a comma? decision,
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.
LGTM
Summary
Add a set of new APIs for forced-decisions to OptimizelyUserContext:
Test plan