diff --git a/lib/splitclient-rb/cache/stores/localhost_split_builder.rb b/lib/splitclient-rb/cache/stores/localhost_split_builder.rb index b8f209ab..1fc2f949 100644 --- a/lib/splitclient-rb/cache/stores/localhost_split_builder.rb +++ b/lib/splitclient-rb/cache/stores/localhost_split_builder.rb @@ -22,7 +22,8 @@ def build_split(feature, treatments) seed: 2_089_907_429, defaultTreatment: 'control_treatment', configurations: build_configurations(treatments), - conditions: build_conditions(treatments) + conditions: build_conditions(treatments), + prerequisites: [] } end diff --git a/lib/splitclient-rb/engine/parser/evaluator.rb b/lib/splitclient-rb/engine/parser/evaluator.rb index ec7636cd..578e1651 100644 --- a/lib/splitclient-rb/engine/parser/evaluator.rb +++ b/lib/splitclient-rb/engine/parser/evaluator.rb @@ -38,6 +38,16 @@ def split_configurations(treatment, split) end def match(split, keys, attributes) + if split.key?(:prerequisites) && !split[:prerequisites].nil? + prerequisites_matcher = SplitIoClient::PrerequisitesMatcher.new(split[:prerequisites], @config.split_logger) + return treatment_hash(Models::Label::PREREQUISITES_NOT_MET, split[:defaultTreatment], split[:changeNumber], split_configurations(split[:defaultTreatment], split)) unless prerequisites_matcher.match?( + matching_key: keys[:matching_key], + bucketing_key: keys[:bucketing_key], + evaluator: self, + attributes: attributes + ) + end + in_rollout = false key = keys[:bucketing_key] ? keys[:bucketing_key] : keys[:matching_key] legacy_algo = (split[:algo] == 1 || split[:algo] == nil) ? true : false diff --git a/spec/integrations/in_memory_client_spec.rb b/spec/integrations/in_memory_client_spec.rb index 2f2024b2..209bd3ac 100644 --- a/spec/integrations/in_memory_client_spec.rb +++ b/spec/integrations/in_memory_client_spec.rb @@ -90,6 +90,30 @@ expect(impressions[1][:treatment][:change_number]).to eq(1_506_703_262_916) end + it 'returns treatments with prereq_flag feature and check impressions' do + stub_request(:get, "https://sdk.split.io/api/splitChanges?s=1.3&since=1506703262916&rbSince=-1").to_return(status: 200, body: 'ok') + client.block_until_ready + expect(client.get_treatment('nico_test', 'prereq_flag')).to eq 'on' + expect(client.get_treatment('bla', 'prereq_flag')).to eq 'off_default' + + sleep 0.5 + impressions = custom_impression_listener.queue + + expect(impressions.size).to eq 2 + + expect(impressions[0][:matching_key]).to eq('nico_test') + expect(impressions[0][:split_name]).to eq('prereq_flag') + expect(impressions[0][:treatment][:treatment]).to eq('on') + expect(impressions[0][:treatment][:label]).to eq('in segment all') + expect(impressions[0][:treatment][:change_number]).to eq(1494593336752) + + expect(impressions[1][:matching_key]).to eq('bla') + expect(impressions[1][:split_name]).to eq('prereq_flag') + expect(impressions[1][:treatment][:treatment]).to eq('off_default') + expect(impressions[1][:treatment][:label]).to eq('prerequisites not met') + expect(impressions[1][:treatment][:change_number]).to eq(1494593336752) + end + it 'returns treatments with Test_Save_1 feature and check impressions' do stub_request(:get, "https://sdk.split.io/api/splitChanges?s=1.3&since=1506703262916&rbSince=-1").to_return(status: 200, body: 'ok') client.block_until_ready diff --git a/spec/test_data/integrations/splits.json b/spec/test_data/integrations/splits.json index 9881fda2..1347a248 100644 --- a/spec/test_data/integrations/splits.json +++ b/spec/test_data/integrations/splits.json @@ -2521,6 +2521,59 @@ "label": "in segment all" } ] + }, + { + "impressionsDisabled": false, + "trafficTypeName": "account", + "name": "prereq_flag", + "prerequisites": [ + {"n": "MAURO_TEST", "ts": ["off"]}, + {"n": "FACUNDO_TEST", "ts": ["on"]} + ], + "trafficAllocation": 100, + "trafficAllocationSeed": -285565213, + "seed": -1992295819, + "status": "ACTIVE", + "killed": false, + "defaultTreatment": "off_default", + "changeNumber": 1494593336752, + "algo": 2, + "conditions": [ + { + "conditionType": "ROLLOUT", + "matcherGroup": { + "combiner": "AND", + "matchers": [ + { + "keySelector": { + "trafficType": "user", + "attribute": null + }, + "matcherType": "ALL_KEYS", + "negate": false, + "userDefinedSegmentMatcherData": null, + "whitelistMatcherData": null, + "unaryNumericMatcherData": null, + "betweenMatcherData": null, + "booleanMatcherData": null, + "dependencyMatcherData": null, + "stringMatcherData": null + } + ] + }, + "partitions": [ + { + "treatment": "on", + "size": 100 + }, + { + "treatment": "off", + "size": 0 + } + ], + "label": "in segment all" + } + ] } ], "s": -1,