Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/splitclient-rb/cache/stores/localhost_split_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions lib/splitclient-rb/engine/parser/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions spec/integrations/in_memory_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions spec/test_data/integrations/splits.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down