Skip to content

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

Merged
merged 15 commits into from
Oct 22, 2021

Conversation

ozayr-zaviar
Copy link
Contributor

@ozayr-zaviar ozayr-zaviar commented Oct 3, 2021

Summary

Add a set of new APIs for forced-decisions to OptimizelyUserContext:

  • SetForcedDecision
  • GetForcedDecision
  • RemoveForcedDecision
  • RemoveAllForcedDecisions

Test plan

  • unit tests for the new APIs
  • FSC tests with new test cases

@ozayr-zaviar ozayr-zaviar removed their assignment Oct 4, 2021
@@ -28,6 +28,7 @@
let(:spy_user_profile_service) { spy('user_profile_service') }
Copy link
Contributor

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

Copy link
Contributor

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:

  1. Async behaviour when setting and getting forced decisions.
  2. Async behaviour when getting and removing forced decisions.
  3. Checking for forced-decision in the fallback-rule. Similarly, for all cases where FindValidatedForcedDecision is used.
  4. Validation for empty rule_key when setting forced decision.

Copy link
Contributor

@jaeopt jaeopt left a 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]
Copy link
Contributor

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
Copy link
Contributor

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'] }
Copy link
Contributor

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?

Copy link
Contributor Author

@ozayr-zaviar ozayr-zaviar Oct 13, 2021

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.

Copy link
Contributor

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.

@coveralls
Copy link

coveralls commented Oct 11, 2021

Coverage Status

Coverage increased (+0.1%) to 99.592% when pulling c3647ad on uzair/forced-decision into a49bc5b on master.

@msohailhussain msohailhussain marked this pull request as ready for review October 11, 2021 19:31
@msohailhussain msohailhussain requested a review from a team as a code owner October 11, 2021 19:31
Copy link
Contributor

@jaeopt jaeopt left a 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'] }
Copy link
Contributor

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.

Copy link
Contributor

@jaeopt jaeopt left a 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)
Copy link
Contributor

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,

Copy link
Contributor

@yasirfolio3 yasirfolio3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@msohailhussain msohailhussain merged commit c778d08 into master Oct 22, 2021
@msohailhussain msohailhussain deleted the uzair/forced-decision branch October 22, 2021 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants