diff --git a/spec/engine_spec.rb b/spec/engine_spec.rb index 72a6999e..1919879c 100644 --- a/spec/engine_spec.rb +++ b/spec/engine_spec.rb @@ -75,7 +75,7 @@ treatment: 'off', config: nil ) - destroy_factory + close_redis end it 'get_treatment returns off' do @@ -94,7 +94,7 @@ expect(subject.get_treatments('nicolas', ['mauro_test'], {})).to eq( mauro_test: 'off' ) - destroy_factory + close_redis end it 'get_treatments_by_flag_set returns off' do @@ -107,7 +107,7 @@ expect(subject.get_treatments_by_flag_set('nicolas', 'set_2', {})).to eq( mauro_test: 'off' ) - destroy_factory + close_redis end it 'get_treatments_by_flag_sets returns off' do @@ -120,7 +120,7 @@ expect(subject.get_treatments_by_flag_sets('nicolas', ['set_2'], {})).to eq( mauro_test: 'off' ) - destroy_factory + close_redis end end @@ -135,7 +135,7 @@ it 'returns CONTROL for random id' do expect(subject.get_treatment('random_user_id', 'my_random_feature')) .to eq SplitIoClient::Engine::Models::Treatment::CONTROL - destroy_factory + close_redis end it 'returns CONTROL and label for incorrect feature name' do @@ -146,20 +146,20 @@ label: SplitIoClient::Engine::Models::Label::NOT_FOUND, change_number: nil ) - destroy_factory + close_redis end it 'returns CONTROL on nil key' do expect(subject.get_treatment(nil, 'test_feature')).to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: you passed a nil key, key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'returns CONTROL on empty key' do expect(subject.get_treatment('', 'test_feature')).to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: you passed an empty matching_key, ' \ 'matching_key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'returns CONTROL on nil matching_key' do @@ -167,7 +167,7 @@ .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string) .to include 'get_treatment: you passed a nil matching_key, matching_key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'returns control on empty matching_key' do @@ -175,7 +175,7 @@ .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: you passed an empty matching_key, ' \ 'matching_key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'returns control on longer than specified max characters matching_key' do @@ -183,7 +183,7 @@ .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: matching_key is too long - ' \ "must be #{subject.instance_variable_get(:@config).max_key_size} characters or less" - destroy_factory + close_redis end it 'logs warning when Numeric matching_key' do @@ -198,7 +198,7 @@ .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: you passed a nil bucketing_key, ' \ 'bucketing_key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'returns control on empty bucketing_key' do @@ -206,7 +206,7 @@ .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: you passed an empty bucketing_key, ' \ 'bucketing_key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'returns control on longer than specified max characters bucketing_key' do @@ -214,7 +214,7 @@ .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: bucketing_key is too long - ' \ "must be #{subject.instance_variable_get(:@config).max_key_size} characters or less" - destroy_factory + close_redis end it 'logs warning when Numeric bucketing_key' do @@ -222,7 +222,7 @@ expect(subject.get_treatment({ bucketing_key: value, matching_key: 'random_user_id' }, 'test_feature')) .to eq 'on' expect(log.string).to include "get_treatment: bucketing_key \"#{value}\" is not of type String, converting" - destroy_factory + close_redis end #TODO We will remove multiple param in the future. @@ -232,7 +232,7 @@ label: nil, change_number: nil ) - destroy_factory + close_redis end it 'returns control on empty key' do @@ -240,7 +240,7 @@ .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: you passed an empty matching_key, ' \ 'matching_key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'returns control on NaN key' do @@ -248,7 +248,7 @@ .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: you passed an invalid matching_key type, ' \ 'matching_key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'returns control on longer than specified max characters key' do @@ -256,33 +256,33 @@ .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: matching_key is too long - ' \ "must be #{subject.instance_variable_get(:@config).max_key_size} characters or less" - destroy_factory + close_redis end it 'logs warning when Numeric key' do value = 123 expect(subject.get_treatment(value, 'test_feature')).to eq 'on' expect(log.string).to include "get_treatment: matching_key \"#{value}\" is not of type String, converting" - destroy_factory + close_redis end it 'returns CONTROL on nil split_name' do expect(subject.get_treatment('random_user_id', nil)).to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: you passed a nil split_name, ' \ 'split_name must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'returns CONTROL on empty split_name' do expect(subject.get_treatment('random_user_id', '')).to eq SplitIoClient::Engine::Models::Treatment::CONTROL - destroy_factory + close_redis end it 'returns CONTROL on number split_name' do expect(subject.get_treatment('random_user_id', 123)).to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: you passed an invalid split_name type, ' \ 'split_name must be a non-empty String or a Symbol' - destroy_factory + close_redis end #TODO We will remove multiple param in the future. @@ -292,21 +292,21 @@ label: nil, change_number: nil ) - destroy_factory + close_redis end it 'trims split_name and logs warning when extra whitespaces' do split_name = ' test_feature ' expect(subject.get_treatment('fake_user_id_1', split_name)).to eq 'on' expect(log.string).to include "get_treatment: feature_flag_name #{split_name} has extra whitespace, trimming" - destroy_factory + close_redis end it 'returns CONTROL when non Hash attributes' do expect(subject.get_treatment('random_user_id', 'test_feature', ["I'm an Array"])) .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: attributes must be of type Hash' - destroy_factory + close_redis end it 'returns CONTROL and logs warning when ready and split does not exist' do @@ -315,7 +315,7 @@ expect(log.string).to include 'get_treatment: you passed non_existing_feature ' \ 'that does not exist in this environment, please double check what feature flags exist ' \ 'in the Split user interface' - destroy_factory + close_redis end it 'returns CONTROL with NOT_READY label when not ready' do @@ -324,7 +324,7 @@ expect(subject.get_treatment('random_user_id', 'test_feature')) .to eq SplitIoClient::Engine::Models::Treatment::CONTROL expect(log.string).to include 'get_treatment: the SDK is not ready, results may be incorrect for feature flag test_feature. Make sure to wait for SDK readiness before using this method' - destroy_factory + close_redis end end @@ -340,7 +340,7 @@ result = subject.get_treatment_with_config('fake_user_id_1', split_name) expect(result[:treatment]).to eq 'on' expect(result[:config]).to eq '{"killed":false}' - destroy_factory + close_redis end it 'returns the default treatment config on killed split' do @@ -348,7 +348,7 @@ result = subject.get_treatment_with_config('fake_user_id_1', split_name) expect(result[:treatment]).to eq 'off' expect(result[:config]).to eq '{"killed":true}' - destroy_factory + close_redis end it 'returns nil when no configs' do @@ -356,7 +356,7 @@ result = subject.get_treatment_with_config('fake_user_id_1', split_name) expect(result[:treatment]).to eq 'on' expect(result[:config]).to eq nil - destroy_factory + close_redis end it 'returns nil when no configs for feature' do @@ -364,7 +364,7 @@ result = subject.get_treatment_with_config('fake_user_id_1', split_name) expect(result[:treatment]).to eq 'on' expect(result[:config]).to eq nil - destroy_factory + close_redis end it 'returns control and logs the correct message on nil key' do @@ -374,7 +374,7 @@ expect(result[:config]).to eq nil expect(log.string) .to include 'get_treatment_with_config: you passed a nil key, key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'returns nil when killed and no configs for default treatment' do @@ -382,7 +382,7 @@ result = subject.get_treatment_with_config('fake_user_id_1', split_name) expect(result[:treatment]).to eq 'off' expect(result[:config]).to eq nil - destroy_factory + close_redis end end @@ -395,39 +395,39 @@ it 'returns empty hash on nil split_names' do expect(subject.get_treatments('random_user_id', nil)).to be_nil expect(log.string).to include 'get_treatments: feature_flag_names must be a non-empty Array' - destroy_factory + close_redis end it 'returns empty hash when no Array split_names' do expect(subject.get_treatments('random_user_id', Object.new)).to be_nil expect(log.string).to include 'get_treatments: feature_flag_names must be a non-empty Array' - destroy_factory + close_redis end it 'returns empty hash on empty array split_names' do expect(subject.get_treatments('random_user_id', [])).to eq({}) expect(log.string).to include 'get_treatments: feature_flag_names must be a non-empty Array' - destroy_factory + close_redis end it 'sanitizes split_names removing repeating and nil split_names' do treatments = subject.get_treatments('random_user_id', ['test_feature', nil, nil, 'test_feature']) expect(treatments.size).to eq 1 - destroy_factory + close_redis end it 'warns when non string split_names' do expect(subject.get_treatments('random_user_id', [Object.new, Object.new])).to eq({}) expect(log.string).to include 'get_treatments: you passed an invalid feature_flag_name, ' \ 'flag name must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'warns when empty split_names' do expect(subject.get_treatments('random_user_id', [''])).to eq({}) expect(log.string).to include 'get_treatments: you passed an empty feature_flag_name, ' \ 'flag name must be a non-empty String or a Symbol' - destroy_factory + close_redis end end @@ -446,7 +446,7 @@ expect(result[:test_feature]).to eq(treatment: 'on', config: '{"killed":false}') expect(result[:no_configs_feature]).to eq(treatment: 'on', config: nil) expect(result[:killed_feature]).to eq(treatment: 'off', config: '{"killed":true}') - destroy_factory + close_redis end end @@ -459,37 +459,37 @@ it 'returns empty hash on nil split_names' do expect(subject.get_treatments_by_flag_set('random_user_id', nil)).to eq({}) expect(log.string).to include 'get_treatments_by_flag_set: you passed an invalid flag set type, flag set must be a non-empty String' - destroy_factory + close_redis end it 'returns empty hash when no Array split_names' do expect(subject.get_treatments_by_flag_set('random_user_id', Object.new)).to eq({}) expect(log.string).to include 'get_treatments_by_flag_set: you passed an invalid flag set type, flag set must be a non-empty String' - destroy_factory + close_redis end it 'returns empty hash on empty array split_names' do expect(subject.get_treatments_by_flag_set('random_user_id', [])).to eq({}) expect(log.string).to include 'get_treatments_by_flag_set: you passed an invalid flag set type, flag set must be a non-empty String' - destroy_factory + close_redis end it 'sanitizes flagset names removing repeating and nil' do treatments = subject.get_treatments_by_flag_set('random_user_id', ['set_1', nil, nil, 'set_1']) expect(treatments.size).to eq 0 - destroy_factory + close_redis end it 'warns when non string flagset names' do expect(subject.get_treatments_by_flag_set('random_user_id', [Object.new, Object.new])).to eq({}) expect(log.string).to include 'get_treatments_by_flag_set: you passed an invalid flag set type, flag set must be a non-empty String' - destroy_factory + close_redis end it 'warns when empty flagset names' do expect(subject.get_treatments_by_flag_set('random_user_id', [''])).to eq({}) expect(log.string).to include 'get_treatments_by_flag_set: you passed an invalid flag set type, flag set must be a non-empty String' - destroy_factory + close_redis end end @@ -503,38 +503,38 @@ it 'returns empty hash on nil split_names' do expect(subject.get_treatments_by_flag_sets('random_user_id', nil)).to eq({}) expect(log.string).to include 'get_treatments_by_flag_sets: FlagSets must be a non-empty list' - destroy_factory + close_redis end it 'returns empty hash when no Array split_names' do expect(subject.get_treatments_by_flag_sets('random_user_id', Object.new)).to eq({}) expect(log.string).to include 'get_treatments_by_flag_sets: FlagSets must be a non-empty list' - destroy_factory + close_redis end it 'returns empty hash on empty array split_names' do expect(subject.get_treatments_by_flag_sets('random_user_id', [])).to eq({}) expect(log.string).to include 'get_treatments_by_flag_sets: FlagSets must be a non-empty list' - destroy_factory + close_redis end it 'sanitizes flagset names removing repeating and nil' do treatments = subject.get_treatments_by_flag_sets('random_user_id', ['set_1', nil, nil, 'set_1']) expect(log.string).to include 'get_treatments_by_flag_sets: you passed a nil flag set, flag set must be a non-empty String' expect(treatments.size).to eq 1 - destroy_factory + close_redis end it 'warns when non string flagset names' do expect(subject.get_treatments_by_flag_sets('random_user_id', [Object.new, Object.new])).to eq({}) expect(log.string).to include 'get_treatments_by_flag_sets: you passed an invalid flag set type, flag set must be a non-empty String' - destroy_factory + close_redis end it 'warns when empty flagset names' do expect(subject.get_treatments_by_flag_sets('random_user_id', [''])).to eq({}) expect(log.string).to include 'get_treatments_by_flag_sets: you passed an invalid flag set type, flag set must be a non-empty String' - destroy_factory + close_redis end end @@ -548,7 +548,7 @@ result = subject.get_treatments_with_config_by_flag_set('fake_user_id_1', 'set_1') expect(result.size).to eq 1 expect(result[:test_feature]).to eq(treatment: 'on', config: '{"killed":false}') - destroy_factory + close_redis end end @@ -562,7 +562,7 @@ result = subject.get_treatments_with_config_by_flag_sets('fake_user_id_1', ['set_1']) expect(result.size).to eq 1 expect(result[:test_feature]).to eq(treatment: 'on', config: '{"killed":false}') - destroy_factory + close_redis end end @@ -575,13 +575,13 @@ it 'validates the feature is on for all ids' do expect(subject.get_treatment('fake_user_id_1', 'test_feature')).to eq 'on' expect(subject.get_treatment('fake_user_id_2', 'test_feature')).to eq 'on' - destroy_factory + close_redis end xit 'allocates minimum objects' do expect { subject.get_treatment('fake_user_id_1', 'test_feature') }.to allocate_max(283).objects expect(subject.get_treatment('fake_user_id_1', 'test_feature')).to eq 'on' - destroy_factory + close_redis end end @@ -595,19 +595,19 @@ it 'validates the feature is on for all ids' do expect(subject.get_treatment('fake_user_id_1', 'new_feature')).to eq 'on' - destroy_factory + close_redis end it 'validates the feature is on for integer' do expect(subject.get_treatment(222, 'new_feature')).to eq 'on' - destroy_factory + close_redis end it 'validates the feature is on for all ids multiple keys' do expect(subject.get_treatments('fake_user_id_1', %w[new_feature foo])).to eq( new_feature: 'on', foo: SplitIoClient::Engine::Models::Treatment::CONTROL ) - destroy_factory + close_redis end it "[#{cache_adapter}] validates the feature is on for all ids multiple keys for integer key" do @@ -617,7 +617,7 @@ impressions = subject.instance_variable_get(:@impressions_repository).batch expect(impressions.size).to eq(1) - destroy_factory + close_redis end it 'validates the feature is on for all ids multiple keys for integer key' do @@ -632,7 +632,7 @@ .new(subject.instance_variable_get(:@impressions_repository)) .call(true, impressions) .select { |im| im[:f] == :new_feature }[0][:i].size).to eq(2) - destroy_factory + close_redis end it 'validates the feature by bucketing_key' do @@ -642,14 +642,14 @@ impressions = subject.instance_variable_get(:@impressions_repository).batch expect(impressions.first[:i][:k]).to eq('fake_user_id_1') - destroy_factory + close_redis end it 'validates the feature by bucketing_key for nil matching_key' do key = { bucketing_key: 'fake_user_id_1' } expect(subject.get_treatment(key, 'new_feature')).to eq 'control' - destroy_factory + close_redis end it 'validates the feature by bucketing_key' do @@ -659,17 +659,17 @@ impressions = subject.instance_variable_get(:@impressions_repository).batch expect(impressions.first[:i][:k]).to eq('222') - destroy_factory + close_redis end it 'validates the feature returns default treatment for non matching ids' do expect(subject.get_treatment('fake_user_id_3', 'new_feature')).to eq 'def_test' - destroy_factory + close_redis end it 'returns default treatment for active splits with a non matching id' do expect(subject.get_treatment('fake_user_id_3', 'new_feature')).to eq 'def_test' - destroy_factory + close_redis end end @@ -689,7 +689,7 @@ new_feature3: 'on', new_feature4: SplitIoClient::Engine::Models::Treatment::CONTROL ) - destroy_factory + close_redis end it 'validates the feature by bucketing_key' do @@ -702,7 +702,7 @@ impressions = subject.instance_variable_get(:@impressions_repository).batch expect(impressions.first[:i][:k]).to eq('fake_user_id_1') - destroy_factory + close_redis end it 'validates the feature by bucketing_key for nil matching_key' do @@ -710,17 +710,17 @@ expect(subject.get_treatments(key, ['new_feature'])) .to eq(new_feature: SplitIoClient::Engine::Models::Treatment::CONTROL) - destroy_factory + close_redis end it 'validates the feature returns default treatment for non matching ids' do expect(subject.get_treatments('fake_user_id_3', ['new_feature'])).to eq(new_feature: 'def_test') - destroy_factory + close_redis end it 'returns default treatment for active splits with a non matching id' do expect(subject.get_treatments('fake_user_id_3', ['new_feature'])).to eq(new_feature: 'def_test') - destroy_factory + close_redis end end @@ -733,12 +733,12 @@ it 'validates the feature is on for all ids' do expect(subject.get_treatment('fake_user_id_1', 'test_whitelist')).to eq 'on' - destroy_factory + close_redis end it 'validates the feature is on for all ids' do expect(subject.get_treatment('fake_user_id_2', 'test_whitelist')).to eq 'off' - destroy_factory + close_redis end end @@ -751,7 +751,7 @@ it 'returns on treatment' do expect(subject.get_treatment('fake_user_id_1', 'test_dependency')).to eq 'on' - destroy_factory + close_redis end it 'produces only 1 impression' do @@ -759,7 +759,7 @@ impressions = subject.instance_variable_get(:@impressions_repository).batch expect(impressions.size).to eq(1) - destroy_factory + close_redis end end @@ -775,7 +775,7 @@ expect(subject.get_treatment('fake_user_id_1', 'test_killed')).to eq 'def_test' expect(subject.get_treatment('fake_user_id_2', 'test_killed')).to eq 'def_test' expect(subject.get_treatment('fake_user_id_3', 'test_killed')).to eq 'def_test' - destroy_factory + close_redis end end @@ -790,7 +790,7 @@ it 'returns control for deleted splits' do expect(subject.get_treatment('fake_user_id_3', 'new_feature')).to eq 'control' - destroy_factory + close_redis end end @@ -824,7 +824,7 @@ expect(range.cover?(treatments[i])).to be true i += 1 end - destroy_factory + close_redis end end @@ -847,7 +847,7 @@ impressions = customer_impression_listener.queue expect(impressions.size >= 2).to be true - destroy_factory + close_redis end it 'returns correct impressions for get_treatments' do @@ -865,7 +865,7 @@ expect(impressions.select { |i| i[:split_name] == :sample_feature }.size).to eq(6) expect(impressions.select { |i| i[:split_name] == :beta_feature }.size).to eq(6) - destroy_factory + close_redis end context 'traffic allocations' do @@ -879,28 +879,28 @@ expect(subject.get_treatment('01', 'Traffic_Allocation_UI')).to eq('off') expect(subject.get_treatment('ab', 'Traffic_Allocation_UI')).to eq('off') expect(subject.get_treatment('00b0', 'Traffic_Allocation_UI')).to eq('off') - destroy_factory + close_redis end it 'returns expected treatment when traffic alllocation < 100' do expect(subject.get_treatment('01', 'Traffic_Allocation_UI3')).to eq('off') expect(subject.get_treatment('ab', 'Traffic_Allocation_UI3')).to eq('off') expect(subject.get_treatment('00b0', 'Traffic_Allocation_UI3')).to eq('off') - destroy_factory + close_redis end it 'returns expected treatment when traffic alllocation is 0' do expect(subject.get_treatment('01', 'Traffic_Allocation_UI4')).to eq('on') expect(subject.get_treatment('ab', 'Traffic_Allocation_UI4')).to eq('on') expect(subject.get_treatment('00b0', 'Traffic_Allocation_UI4')).to eq('on') - destroy_factory + close_redis end it 'returns "not in split" label' do subject.get_treatment('test', 'Traffic_Allocation_UI2') impressions_repository = subject.instance_variable_get(:@impressions_repository) expect(impressions_repository.batch[0][:i][:r]).to eq(SplitIoClient::Engine::Models::Label::NOT_IN_SPLIT) - destroy_factory + close_redis end end end @@ -916,7 +916,7 @@ allow_any_instance_of(SplitIoClient::Splitter).to receive(:bucket).and_return(1) subject.block_until_ready expect(subject.get_treatment('test', 'Traffic_Allocation_One_Percent')).to eq('on') - destroy_factory + close_redis end end @@ -932,7 +932,8 @@ subject.block_until_ready expect(subject.get_treatment('fake_user_id_1', 'test_feature')).to eq 'on' sleep 0.5 - destroy_factory + close_redis + subject.destroy expect(subject.get_treatment('fake_user_id_1', 'test_feature')).to eq 'control' end end @@ -946,7 +947,7 @@ it 'returns control' do allow(subject.instance_variable_get(:@impressions_repository)) .to receive(:add).and_raise(Redis::CannotConnectError) - destroy_factory + close_redis end end @@ -976,7 +977,7 @@ ) expect(subject.instance_variable_get(:@events_repository).clear).to eq([]) - destroy_factory + close_redis end end @@ -991,28 +992,28 @@ expect(subject.instance_variable_get(:@events_repository)).not_to receive(:add) expect(subject.track(nil, 'traffic_type', 'event_type', 123)).to be false expect(log.string).to include 'track: you passed a nil key, key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'event is not added when empty key' do expect(subject.instance_variable_get(:@events_repository)).not_to receive(:add) expect(subject.track('', 'traffic_type', 'event_type', 123)).to be false expect(log.string).to include 'track: you passed an empty key, key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'event is not added when nil key' do expect(subject.instance_variable_get(:@events_repository)).not_to receive(:add) expect(subject.track(nil, 'traffic_type', 'event_type', 123)).to be false expect(log.string).to include 'track: you passed a nil key, key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'event is not added when no Integer, String or Symbol key' do expect(subject.instance_variable_get(:@events_repository)).not_to receive(:add) expect(subject.track(Object.new, 'traffic_type', 'event_type', 123)).to be false expect(log.string).to include 'track: you passed an invalid key type, key must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'event is not added when longer than specified max characters key' do @@ -1020,7 +1021,7 @@ expect(subject.track(very_long_key, 'traffic_type', 'event_type', 123)).to be false expect(log.string).to include 'track: key is too long - ' \ "must be #{subject.instance_variable_get(:@config).max_key_size} characters or less" - destroy_factory + close_redis end it 'event is added and a Warn is logged when Integer key' do @@ -1029,7 +1030,7 @@ value = 123 expect(subject.track(value, 'traffic_type', 'event_type', 123)).to be true expect(log.string).to include "track: key \"#{value}\" is not of type String, converting" - destroy_factory + close_redis end it 'event is not added when nil traffic_type_name' do @@ -1037,7 +1038,7 @@ expect(subject.track(1, nil, 'event_type', 123)).to be false expect(log.string).to include 'track: you passed a nil traffic_type_name, ' \ 'traffic_type_name must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'event is not added when empty string traffic_type_name' do @@ -1045,7 +1046,7 @@ expect(subject.track(1, '', 'event_type', 123)).to be false expect(log.string).to include 'track: you passed an empty traffic_type_name, ' \ 'traffic_type_name must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'event is added and a Warn is logged when capitalized traffic_type_name' do @@ -1055,7 +1056,7 @@ expect(subject.track('key', 'TRAFFIC_TYPE', 'event_type', 123)).to be true expect(log.string).to include 'track: traffic_type_name should be all lowercase - ' \ 'converting string to lowercase' - destroy_factory + close_redis end it 'event is not added when nil event_type' do @@ -1063,7 +1064,7 @@ expect(subject.track('key', 'traffic_type', nil, 123)).to be false expect(log.string).to include 'track: you passed a nil event_type, ' \ 'event_type must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'event is not added when no String or Symbol event_type' do @@ -1071,7 +1072,7 @@ expect(subject.track('key', 'traffic_type', Object.new, 123)).to be false expect(log.string).to include 'track: you passed an invalid event_type type, ' \ 'event_type must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'event is not added when empty event_type' do @@ -1079,7 +1080,7 @@ expect(subject.track('key', 'traffic_type', '', 123)).to be false expect(log.string).to include 'track: you passed an empty event_type, ' \ 'event_type must be a non-empty String or a Symbol' - destroy_factory + close_redis end it 'event is not added when event_type does not conform with specified format' do @@ -1087,34 +1088,34 @@ expect(subject.track('key', 'traffic_type', 'foo@bar', 123)).to be false expect(log.string).to include 'event_type must adhere to the regular expression ' \ '^[a-zA-Z0-9][-_.:a-zA-Z0-9]{0,79}$. ' - destroy_factory + close_redis end it 'event is not added when no Integer value' do expect(subject.instance_variable_get(:@events_repository)).not_to receive(:add) expect(subject.track('key', 'traffic_type', 'event_type', 'non-integer')).to be false expect(log.string).to include 'track: value must be Numeric' - destroy_factory + close_redis end it 'event is added when nil value' do expect(subject.instance_variable_get(:@events_repository)).to receive(:add) expect(subject.track('key', 'traffic_type', 'event_type', nil)).to be true - destroy_factory + close_redis end it 'event is not added when non Hash properties' do expect(subject.instance_variable_get(:@events_repository)).not_to receive(:add) expect(subject.track('key', 'traffic_type', 'event_type', 123, 'not a Hash')).to be false expect(log.string).to include 'track: properties must be a Hash' - destroy_factory + close_redis end it 'event is not added when error calling add' do expect(subject.instance_variable_get(:@events_repository)).to receive(:add).and_throw(StandardError) expect(subject.track('key', 'traffic_type', 'event_type', 123)).to be false expect(log.string).to include '[splitclient-rb] Unexpected exception in track' - destroy_factory + close_redis end it 'warns users when property count exceeds 300' do @@ -1124,7 +1125,7 @@ expect(subject.instance_variable_get(:@events_repository)).to receive(:add) expect(subject.track('key', 'traffic_type', 'event_type', 123, properties)).to be true expect(log.string).to include 'Event has more than 300 properties. Some of them will be trimmed when processed' - destroy_factory + close_redis end it 'removes non String key properties' do @@ -1136,7 +1137,7 @@ .to eq [properties.select { |key, _| key.is_a?(String) }, 5] expect(subject.instance_variable_get(:@events_repository)).to receive(:add) expect(subject.track('key', 'traffic_type', 'event_type', 123, properties)).to be true - destroy_factory + close_redis end it 'changes invalid property values to nil' do @@ -1152,7 +1153,7 @@ expect(subject.instance_variable_get(:@events_repository)).to receive(:add) expect(subject.track('key', 'traffic_type', 'event_type', 123, properties)).to be true expect(log.string).to include 'Property invalid_property_value is of invalid type. Setting value to nil' - destroy_factory + close_redis end it 'event is not added when properties size exceeds threshold' do @@ -1162,7 +1163,7 @@ expect(subject.track('key', 'traffic_type', 'event_type', 123, properties)).to be false expect(log.string).to include 'The maximum size allowed for the properties is 32768. ' \ 'Current is 33078. Event not queued' - destroy_factory + close_redis end it 'event is added and a Warn is logged when traffic type does not exist' do @@ -1175,7 +1176,7 @@ expect(log.string).to include "track: Traffic Type #{traffic_type_name} " \ "does not have any corresponding feature flags in this environment, make sure you're tracking " \ 'your events to a valid traffic type defined in the Split user interface' - destroy_factory + close_redis end end end @@ -1307,11 +1308,10 @@ def add_flag_sets_to_redis(flag_sets_json) end end -def destroy_factory +def close_redis config = subject.instance_variable_get(:@config) if config.cache_adapter.is_a? SplitIoClient::Cache::Adapters::RedisAdapter redis = config.cache_adapter.instance_variable_get(:@redis) redis.close end - subject.destroy end