Skip to content

Commit f5da2a7

Browse files
authored
Merge pull request #553 from splitio/rbs-oldspec-restore-since
updated split api
2 parents 1566bfb + ecd007b commit f5da2a7

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

lib/splitclient-rb/engine/api/splits.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def initialize(api_key, config, telemetry_runtime_producer)
1616
@spec_version = SplitIoClient::Spec::FeatureFlags::SPEC_VERSION
1717
@last_proxy_check_timestamp = 0
1818
@clear_storage = false
19+
@old_spec_since = nil
1920
end
2021

2122
def since(since, since_rbs, fetch_options = { cache_control_headers: false, till: nil, sets: nil})
@@ -24,13 +25,16 @@ def since(since, since_rbs, fetch_options = { cache_control_headers: false, till
2425
if check_last_proxy_check_timestamp
2526
@spec_version = SplitIoClient::Spec::FeatureFlags::SPEC_VERSION
2627
@config.logger.debug("Switching to new Feature flag spec #{@spec_version} and fetching.")
28+
@old_spec_since = since
2729
since = -1
2830
since_rbs = -1
2931
fetch_options = { cache_control_headers: false, till: nil, sets: nil}
3032
end
3133

3234
if @spec_version == Splits::SPEC_1_1
35+
since = @old_spec_since unless @old_spec_since.nil?
3336
params = { s: @spec_version, since: since }
37+
@old_spec_since = nil
3438
else
3539
params = { s: @spec_version, since: since, rbSince: since_rbs }
3640
end

spec/engine/api/splits_spec.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,38 @@
225225

226226
SplitIoClient::Api::Splits::PROXY_CHECK_INTERVAL_SECONDS = 1
227227
sleep 1
228-
parsed_splits = splits_api.since(-1, -1)
228+
parsed_splits = splits_api.since(1457726098069, -1)
229229
expect(splits_api.clear_storage).to eq(true)
230230
expect(parsed_splits[:ff][:d].length()).to eq(2)
231231
expect(parsed_splits[:rbs][:d].length()).to eq(1)
232232
expect(splits_api.instance_variable_get(:@spec_version)).to eq(SplitIoClient::Spec::FeatureFlags::SPEC_VERSION)
233+
expect(splits_api.instance_variable_get(:@old_spec_since)).to eq(1457726098069)
234+
end
235+
236+
it 'check using old_spec_since variable' do
237+
old_spec_splits2 = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../../test_data/rule_based_segments/split_old_spec2.json')))
238+
239+
stub_request(:get, 'https://proxy-server/api/splitChanges?s=1.3&since=-1&rbSince=-1')
240+
.to_return({status: 400, body: ''}, {status: 400, body: ''})
241+
stub_request(:get, 'https://proxy-server/api/splitChanges?s=1.1&since=-1')
242+
.to_return(status: 200, body: old_spec_splits)
243+
stub_request(:get, 'https://proxy-server/api/splitChanges?s=1.1&since=1457726098069')
244+
.to_return(status: 200, body: old_spec_splits2)
245+
246+
parsed_splits = splits_api.since(-1, -1)
247+
expect(parsed_splits[:ff][:d].length()).to eq(6)
248+
expect(splits_api.instance_variable_get(:@spec_version)).to eq(SplitIoClient::Api::Splits::SPEC_1_1)
249+
250+
SplitIoClient::Api::Splits::PROXY_CHECK_INTERVAL_SECONDS = 1
251+
sleep 1
252+
parsed_splits = splits_api.since(1457726098069, -1)
253+
SplitIoClient::Api::Splits::PROXY_CHECK_INTERVAL_SECONDS = 100000
254+
255+
sleep 1
256+
expect(splits_api.instance_variable_get(:@spec_version)).to eq(SplitIoClient::Api::Splits::SPEC_1_1)
257+
expect(splits_api.instance_variable_get(:@old_spec_since)).to eq(nil)
258+
expect(parsed_splits[:ff][:d].length()).to eq(1)
259+
expect(log.string).to include 'Switching to new Feature flag spec 1.3 and fetching.'
233260
end
234261
end
235262
end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"splits": [
3+
{
4+
"orgId": null,
5+
"environment": null,
6+
"trafficTypeId": null,
7+
"trafficTypeName": null,
8+
"name": "new_feature",
9+
"seed": -1222652054,
10+
"status": "ACTIVE",
11+
"killed": false,
12+
"changeNumber": 123,
13+
"defaultTreatment": "off",
14+
"conditions": [
15+
{
16+
"matcherGroup": {
17+
"combiner": "AND",
18+
"matchers": [
19+
{
20+
"matcherType": "WHITELIST",
21+
"negate": false,
22+
"userDefinedSegmentMatcherData": null,
23+
"whitelistMatcherData": {
24+
"whitelist": [
25+
"whitelisted_user"
26+
]
27+
}
28+
}
29+
]
30+
},
31+
"partitions": [
32+
{
33+
"treatment": "on",
34+
"size": 100
35+
}
36+
]
37+
},
38+
{
39+
"matcherGroup": {
40+
"combiner": "AND",
41+
"matchers": [
42+
{
43+
"matcherType": "ALL_KEYS",
44+
"negate": false,
45+
"userDefinedSegmentMatcherData": null,
46+
"whitelistMatcherData": null
47+
}
48+
]
49+
},
50+
"partitions": [
51+
{
52+
"treatment": "on",
53+
"size": 0
54+
},
55+
{
56+
"treatment": "off",
57+
"size": 100
58+
}
59+
]
60+
}
61+
],
62+
"sets": ["set1", "set2"]
63+
} ],
64+
"since": -1,
65+
"till": 1457726098069
66+
}

0 commit comments

Comments
 (0)