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
4 changes: 4 additions & 0 deletions lib/splitclient-rb/engine/api/splits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def initialize(api_key, config, telemetry_runtime_producer)
@spec_version = SplitIoClient::Spec::FeatureFlags::SPEC_VERSION
@last_proxy_check_timestamp = 0
@clear_storage = false
@old_spec_since = nil
end

def since(since, since_rbs, fetch_options = { cache_control_headers: false, till: nil, sets: nil})
Expand All @@ -24,13 +25,16 @@ def since(since, since_rbs, fetch_options = { cache_control_headers: false, till
if check_last_proxy_check_timestamp
@spec_version = SplitIoClient::Spec::FeatureFlags::SPEC_VERSION
@config.logger.debug("Switching to new Feature flag spec #{@spec_version} and fetching.")
@old_spec_since = since
since = -1
since_rbs = -1
fetch_options = { cache_control_headers: false, till: nil, sets: nil}
end

if @spec_version == Splits::SPEC_1_1
since = @old_spec_since unless @old_spec_since.nil?
params = { s: @spec_version, since: since }
@old_spec_since = nil
else
params = { s: @spec_version, since: since, rbSince: since_rbs }
end
Expand Down
29 changes: 28 additions & 1 deletion spec/engine/api/splits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,38 @@

SplitIoClient::Api::Splits::PROXY_CHECK_INTERVAL_SECONDS = 1
sleep 1
parsed_splits = splits_api.since(-1, -1)
parsed_splits = splits_api.since(1457726098069, -1)
expect(splits_api.clear_storage).to eq(true)
expect(parsed_splits[:ff][:d].length()).to eq(2)
expect(parsed_splits[:rbs][:d].length()).to eq(1)
expect(splits_api.instance_variable_get(:@spec_version)).to eq(SplitIoClient::Spec::FeatureFlags::SPEC_VERSION)
expect(splits_api.instance_variable_get(:@old_spec_since)).to eq(1457726098069)
end

it 'check using old_spec_since variable' do
old_spec_splits2 = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../../test_data/rule_based_segments/split_old_spec2.json')))

stub_request(:get, 'https://proxy-server/api/splitChanges?s=1.3&since=-1&rbSince=-1')
.to_return({status: 400, body: ''}, {status: 400, body: ''})
stub_request(:get, 'https://proxy-server/api/splitChanges?s=1.1&since=-1')
.to_return(status: 200, body: old_spec_splits)
stub_request(:get, 'https://proxy-server/api/splitChanges?s=1.1&since=1457726098069')
.to_return(status: 200, body: old_spec_splits2)

parsed_splits = splits_api.since(-1, -1)
expect(parsed_splits[:ff][:d].length()).to eq(6)
expect(splits_api.instance_variable_get(:@spec_version)).to eq(SplitIoClient::Api::Splits::SPEC_1_1)

SplitIoClient::Api::Splits::PROXY_CHECK_INTERVAL_SECONDS = 1
sleep 1
parsed_splits = splits_api.since(1457726098069, -1)
SplitIoClient::Api::Splits::PROXY_CHECK_INTERVAL_SECONDS = 100000

sleep 1
expect(splits_api.instance_variable_get(:@spec_version)).to eq(SplitIoClient::Api::Splits::SPEC_1_1)
expect(splits_api.instance_variable_get(:@old_spec_since)).to eq(nil)
expect(parsed_splits[:ff][:d].length()).to eq(1)
expect(log.string).to include 'Switching to new Feature flag spec 1.3 and fetching.'
end
end
end
66 changes: 66 additions & 0 deletions spec/test_data/rule_based_segments/split_old_spec2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"splits": [
{
"orgId": null,
"environment": null,
"trafficTypeId": null,
"trafficTypeName": null,
"name": "new_feature",
"seed": -1222652054,
"status": "ACTIVE",
"killed": false,
"changeNumber": 123,
"defaultTreatment": "off",
"conditions": [
{
"matcherGroup": {
"combiner": "AND",
"matchers": [
{
"matcherType": "WHITELIST",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": {
"whitelist": [
"whitelisted_user"
]
}
}
]
},
"partitions": [
{
"treatment": "on",
"size": 100
}
]
},
{
"matcherGroup": {
"combiner": "AND",
"matchers": [
{
"matcherType": "ALL_KEYS",
"negate": false,
"userDefinedSegmentMatcherData": null,
"whitelistMatcherData": null
}
]
},
"partitions": [
{
"treatment": "on",
"size": 0
},
{
"treatment": "off",
"size": 100
}
]
}
],
"sets": ["set1", "set2"]
} ],
"since": -1,
"till": 1457726098069
}