Skip to content

Commit a10f235

Browse files
authored
Merge pull request #557 from splitio/T-FME-4160-prereq-integrations
Added integration tests
2 parents 70c5759 + b430ac4 commit a10f235

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

lib/splitclient-rb/cache/stores/localhost_split_builder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def build_split(feature, treatments)
2222
seed: 2_089_907_429,
2323
defaultTreatment: 'control_treatment',
2424
configurations: build_configurations(treatments),
25-
conditions: build_conditions(treatments)
25+
conditions: build_conditions(treatments),
26+
prerequisites: []
2627
}
2728
end
2829

lib/splitclient-rb/engine/parser/evaluator.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ def split_configurations(treatment, split)
3838
end
3939

4040
def match(split, keys, attributes)
41+
if split.key?(:prerequisites) && !split[:prerequisites].nil?
42+
prerequisites_matcher = SplitIoClient::PrerequisitesMatcher.new(split[:prerequisites], @config.split_logger)
43+
return treatment_hash(Models::Label::PREREQUISITES_NOT_MET, split[:defaultTreatment], split[:changeNumber], split_configurations(split[:defaultTreatment], split)) unless prerequisites_matcher.match?(
44+
matching_key: keys[:matching_key],
45+
bucketing_key: keys[:bucketing_key],
46+
evaluator: self,
47+
attributes: attributes
48+
)
49+
end
50+
4151
in_rollout = false
4252
key = keys[:bucketing_key] ? keys[:bucketing_key] : keys[:matching_key]
4353
legacy_algo = (split[:algo] == 1 || split[:algo] == nil) ? true : false

spec/integrations/in_memory_client_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,30 @@
9090
expect(impressions[1][:treatment][:change_number]).to eq(1_506_703_262_916)
9191
end
9292

93+
it 'returns treatments with prereq_flag feature and check impressions' do
94+
stub_request(:get, "https://sdk.split.io/api/splitChanges?s=1.3&since=1506703262916&rbSince=-1").to_return(status: 200, body: 'ok')
95+
client.block_until_ready
96+
expect(client.get_treatment('nico_test', 'prereq_flag')).to eq 'on'
97+
expect(client.get_treatment('bla', 'prereq_flag')).to eq 'off_default'
98+
99+
sleep 0.5
100+
impressions = custom_impression_listener.queue
101+
102+
expect(impressions.size).to eq 2
103+
104+
expect(impressions[0][:matching_key]).to eq('nico_test')
105+
expect(impressions[0][:split_name]).to eq('prereq_flag')
106+
expect(impressions[0][:treatment][:treatment]).to eq('on')
107+
expect(impressions[0][:treatment][:label]).to eq('in segment all')
108+
expect(impressions[0][:treatment][:change_number]).to eq(1494593336752)
109+
110+
expect(impressions[1][:matching_key]).to eq('bla')
111+
expect(impressions[1][:split_name]).to eq('prereq_flag')
112+
expect(impressions[1][:treatment][:treatment]).to eq('off_default')
113+
expect(impressions[1][:treatment][:label]).to eq('prerequisites not met')
114+
expect(impressions[1][:treatment][:change_number]).to eq(1494593336752)
115+
end
116+
93117
it 'returns treatments with Test_Save_1 feature and check impressions' do
94118
stub_request(:get, "https://sdk.split.io/api/splitChanges?s=1.3&since=1506703262916&rbSince=-1").to_return(status: 200, body: 'ok')
95119
client.block_until_ready

spec/test_data/integrations/splits.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,59 @@
25212521
"label": "in segment all"
25222522
}
25232523
]
2524+
},
2525+
{
2526+
"impressionsDisabled": false,
2527+
"trafficTypeName": "account",
2528+
"name": "prereq_flag",
2529+
"prerequisites": [
2530+
{"n": "MAURO_TEST", "ts": ["off"]},
2531+
{"n": "FACUNDO_TEST", "ts": ["on"]}
2532+
],
2533+
"trafficAllocation": 100,
2534+
"trafficAllocationSeed": -285565213,
2535+
"seed": -1992295819,
2536+
"status": "ACTIVE",
2537+
"killed": false,
2538+
"defaultTreatment": "off_default",
2539+
"changeNumber": 1494593336752,
2540+
"algo": 2,
2541+
"conditions": [
2542+
{
2543+
"conditionType": "ROLLOUT",
2544+
"matcherGroup": {
2545+
"combiner": "AND",
2546+
"matchers": [
2547+
{
2548+
"keySelector": {
2549+
"trafficType": "user",
2550+
"attribute": null
2551+
},
2552+
"matcherType": "ALL_KEYS",
2553+
"negate": false,
2554+
"userDefinedSegmentMatcherData": null,
2555+
"whitelistMatcherData": null,
2556+
"unaryNumericMatcherData": null,
2557+
"betweenMatcherData": null,
2558+
"booleanMatcherData": null,
2559+
"dependencyMatcherData": null,
2560+
"stringMatcherData": null
2561+
}
2562+
]
2563+
},
2564+
"partitions": [
2565+
{
2566+
"treatment": "on",
2567+
"size": 100
2568+
},
2569+
{
2570+
"treatment": "off",
2571+
"size": 0
2572+
}
2573+
],
2574+
"label": "in segment all"
2575+
}
2576+
]
25242577
}
25252578
],
25262579
"s": -1,

0 commit comments

Comments
 (0)