Skip to content

Commit

Permalink
FFM-7871 - Only first prereq is being processed (#26)
Browse files Browse the repository at this point in the history
FFM-7871 - Only first prereq is being processed (#26)

What
Fix prereq loop not to abort too soon, allowing subsequent prereqs to be processed

Why
The old logic aborts immediately after the first iteration of the loop

Testing
The following testgrid test cases are now working:

"Type=NumWith2JSON;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOff;Return 0.11",
"Type=NumWith2JSON;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOnToo;Return 0.11",
"Type=NumWithNumJSON;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOff;Return 0.11",
"Type=NumWithNumJSON;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOnToo;Return 0.11",
"Type=NumWithNumStr;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOnToo;Return 0.11",
"Type=NumWithNumStr;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOff;Return 0.11",
"Type=JSONWith2Bool;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOnToo;Return Val",
"Type=JSONWith2Str;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOff;Return Val",
"Type=JSONWith2Str;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOnToo;Return Val",
"Type=JSONWithJSONStr;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOff;Return Val",
"Type=JSONWithJSONStr;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOnToo;Return Val",

"Type=NumWith2Str;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOff;Return 0.11",
"Type=NumWith2Str;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOnToo;Return 0.11",
"Type=NumWith2JSON;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOff;Return 0.11",
"Type=NumWith2JSON;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOnToo;Return 0.11",
"Type=NumWith2Bool;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOff;Return 0.11",
"Type=NumWith2Bool;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOnToo;Return 0.11",
"Type=NumWith2Num;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOff;Return 0.11",
"Type=NumWith2Num;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOnToo;Return 0.11",
"Type=NumWithNumJSON;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOff;Return 0.11",
"Type=NumWithNumJSON;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOnToo;Return 0.11",
"Type=NumWithNumBool;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOff;Return 0.11",
"Type=NumWithNumBool;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOnToo;Return 0.11",
"Type=NumWithNumStr;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOff;Return 0.11",
"Type=NumWithNumStr;State=Enabled;On=2;Off=0.11;Prereq=AlwaysOn;AlwaysOnToo;Return 0.11",

"Type=JSONWith2Bool;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOff;Return Val",
"Type=JSONWith2JSON;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOff;Return Val",
"Type=JSONWith2JSON;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOnToo;Return Val",
"Type=JSONWith2Num;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOff;Return Val",
"Type=JSONWith2Num;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOnToo;Return Val",
"Type=JSONWithJSONBool;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOff;Return Val",
"Type=JSONWithJSONBool;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOnToo;Return Val",
"Type=JSONWithJSONNum;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOff;Return Val",
"Type=JSONWithJSONNum;State=Enabled;On=Com;Off=Val;Prereq=AlwaysOn;AlwaysOnToo;Return Val",
"Type=BoolWithBoolNum;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOff;Return False",
"Type=BoolWithBoolNum;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOnToo;Return False",
"Type=BoolWith2Bool;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOnToo;Return False",
"Type=BoolWith2Num;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOff;Return False",
"Type=BoolWith2Num;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOnToo;Return False",
"Type=BoolWith2Bool;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOff;Return False",
"Type=BoolWith2Bool;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOnToo;Return False",

"Type=BoolWith2JSON;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOff;Return False",
"Type=BoolWith2JSON;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOnToo;Return False",
"Type=BoolWith2Str;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOnToo;Return False",
"Type=BoolWithBoolJSON;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOnToo;Return False",
"Type=BoolWithBoolJSON;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOff;Return False",

"Type=BoolWithBoolStr;State=Enabled;On=True;Off=False;Prereq=AlwaysOn;AlwaysOnToo;Return False",
  • Loading branch information
andybharness authored May 16, 2023
1 parent 1b45b54 commit 64dabb8
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions lib/ff/ruby/server/sdk/api/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,60 +466,47 @@ def check_pre_requisite(parent_feature_config, target)
prerequisites = parent_feature_config.prerequisites

if prerequisites != nil && !prerequisites.empty?
@logger.debug "Checking prerequisite #{prerequisites.to_s} of flag #{parent_feature_config.feature}"

@logger.debug "Checking pre requisites " + prerequisites.to_s + " of parent feature " + parent_feature_config.feature.to_s

prerequisites.each do |pqs|

pre_req_feature = pqs.feature

pre_req_feature_config = @repository.get_flag(pre_req_feature)

if pre_req_feature_config == nil

@logger.debug "Could not retrieve the pre requisite details of feature flag: " + pre_req_feature.to_s
prerequisites.each do |pre_req|
pre_req_flag = @repository.get_flag(pre_req.feature)

if pre_req_flag == nil
@logger.debug "Could not retrieve the pre requisite details of feature flag: #{pre_req.feature}"
return true
end

pre_req_evaluated_variation = evaluate_flag(pre_req_feature_config, target)

if pre_req_evaluated_variation == nil

@logger.debug "Could not evaluate the prerequisite details of feature flag: " + pre_req_feature.to_s
evaluated_pre_req = evaluate_flag(pre_req_flag, target)

if evaluated_pre_req == nil
@logger.debug "Could not evaluate the prerequisite details of feature flag: #{pre_req.feature}"
return true
end

@logger.debug "Pre requisite flag " + pre_req_feature_config.feature + " has variation " +
pre_req_evaluated_variation.to_s + " for target " + target.to_s

valid_pre_req_variations = pqs.variations

@logger.debug "Pre requisite flag " + pre_req_feature_config.to_s + " should have the variations " +
valid_pre_req_variations.to_s

none_match = true

valid_pre_req_variations.each do |element|

if element.include?(pre_req_evaluated_variation.identifier)

pre_req.variations.each do |next_variation|
if next_variation.include?(evaluated_pre_req.identifier)
none_match = false
break
end
end

if none_match

@logger.debug "Prerequisite flag #{pre_req_flag.feature} has no matching variations for flag #{parent_feature_config.feature}"
return false
else

return check_pre_requisite(pre_req_feature_config, target)
unless check_pre_requisite(pre_req_flag, target)
@logger.debug "Prerequisite flag #{pre_req_flag.feature} is switched off for flag #{parent_feature_config.feature}"
return false
end
end
end
end # prerequisites.each

@logger.debug "All prerequisite flags are switched on for flag #{parent_feature_config.feature}"
return true
end

@logger.debug "No prerequisite flags present for flag #{parent_feature_config.feature}, skipped"
true
end

Expand Down

0 comments on commit 64dabb8

Please sign in to comment.