Skip to content

Commit cb7cb8d

Browse files
authored
Merge pull request #475 from splitio/spec-polishing
Added client.destroy and stub telemetry and event urls
2 parents b1e0430 + 1c5cbf8 commit cb7cb8d

11 files changed

Lines changed: 215 additions & 81 deletions

spec/engine/matchers/between_matcher_spec.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe SplitIoClient::BetweenMatcher do
66
subject do
7-
SplitIoClient::SplitFactory.new('test_api_key', logger: Logger.new('/dev/null'), streaming_enabled: false).client
7+
SplitIoClient::SplitFactory.new('test_api_key', {logger: Logger.new('/dev/null'), streaming_enabled: false, impressions_refresh_rate: 9999, impressions_mode: :none, features_refresh_rate: 9999, telemetry_refresh_rate: 99999}).client
88
end
99

1010
let(:datetime_matcher_splits) do
@@ -27,19 +27,21 @@
2727
let(:missing_key_attributes) { {} }
2828
let(:nil_attributes) { nil }
2929

30+
before do
31+
stub_request(:any, /https:\/\/telemetry.*/).to_return(status: 200, body: 'ok')
32+
stub_request(:any, /https:\/\/events.*/).to_return(status: 200, body: "", headers: {})
33+
end
34+
3035
context 'between positive numbers' do
3136
let(:matching_inclusive_low_attributes) { { income: 100 } }
3237
let(:matching_inclusive_high_attributes) { { income: 120 } }
3338
let(:non_matching_low_value_attributes) { { income: 99 } }
3439

3540
before do
36-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
41+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
3742
.to_return(status: 200, body: number_matcher_splits)
38-
39-
stub_request(:post, 'https://telemetry.split.io/api/v1/metrics/config')
40-
.to_return(status: 200, body: 'ok')
41-
4243
subject.block_until_ready
44+
sleep 1
4345
end
4446

4547
it 'validates the treatment is ON for correct number attribute value' do
@@ -62,13 +64,10 @@
6264
let(:non_matching_low_value_negative_attributes) { { income: -999 } }
6365

6466
before do
65-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
67+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since.*/)
6668
.to_return(status: 200, body: negative_number_matcher_splits)
67-
68-
stub_request(:post, 'https://telemetry.split.io/api/v1/metrics/config')
69-
.to_return(status: 200, body: 'ok')
70-
7169
subject.block_until_ready
70+
sleep 1
7271
end
7372

7473
it 'validates the treatment is ON for correct negative numbers attribute value' do
@@ -93,13 +92,10 @@
9392
let(:non_matching_high_value_attributes) { { created: 1_459_775_460 } } # "2016/04/04T13:11Z"
9493

9594
before do
96-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
95+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
9796
.to_return(status: 200, body: datetime_matcher_splits)
98-
99-
stub_request(:post, 'https://telemetry.split.io/api/v1/metrics/config')
100-
.to_return(status: 200, body: 'ok')
101-
10297
subject.block_until_ready
98+
sleep 1
10399
end
104100

105101
it 'validates the treatment is ON for correct number attribute value' do
@@ -117,10 +113,18 @@
117113
end
118114

119115
context '#string_type' do
116+
before do
117+
stub_request(:get, /https:\/\/sdk.*/)
118+
.to_return(status: 200, body: 'ok')
119+
sleep 1
120+
end
121+
120122
it 'is not string type matcher' do
121123
expect(described_class.new({ attribute: 'foo', data_type: 'NUMBER',
122124
start_value: 0, end_value: 10 }, @split_logger, @split_validator).string_type?)
123125
.to be false
126+
sleep 1
127+
subject.destroy()
124128
end
125129
end
126130
end

spec/engine/matchers/combining_matcher_spec.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe SplitIoClient::CombiningMatcher do
66
subject do
7-
SplitIoClient::SplitFactory.new('test_api_key', logger: Logger.new('/dev/null'), streaming_enabled: false).client
7+
SplitIoClient::SplitFactory.new('test_api_key', {logger: Logger.new('/dev/null'), streaming_enabled: false, impressions_refresh_rate: 9999, impressions_mode: :none, features_refresh_rate: 9999, telemetry_refresh_rate: 99999}).client
88
end
99

1010
let(:splits_json) do
@@ -19,8 +19,13 @@
1919
before do
2020
stub_request(:get, 'https://sdk.split.io/api/segmentChanges/employees?since=-1')
2121
.to_return(status: 200, body: segments_json)
22-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
22+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
2323
.to_return(status: 200, body: splits_json)
24+
stub_request(:any, /https:\/\/telemetry.*/)
25+
.to_return(status: 200, body: 'ok')
26+
stub_request(:any, /https:\/\/events.*/)
27+
.to_return(status: 200, body: 'ok')
28+
sleep 1
2429
end
2530

2631
describe 'anding' do
@@ -33,6 +38,8 @@
3338
'join' => 1_461_283_200,
3439
'custom_attribute' => 'usa'
3540
)).to eq('V-YZKS')
41+
sleep 1
42+
subject.destroy()
3643
end
3744
end
3845
end

spec/engine/matchers/equal_to_matcher_spec.rb

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe SplitIoClient::EqualToMatcher do
66
subject do
7-
SplitIoClient::SplitFactory.new('test_api_key', logger: Logger.new('/dev/null'), streaming_enabled: false).client
7+
SplitIoClient::SplitFactory.new('test_api_key', {logger: Logger.new('/dev/null'), streaming_enabled: false, impressions_refresh_rate: 9999, impressions_mode: :none, features_refresh_rate: 9999, telemetry_refresh_rate: 99999}).client
88
end
99

1010
let(:date_splits_json) do
@@ -35,8 +35,13 @@
3535
let(:matching_attributes) { { age: 30 } }
3636

3737
before do
38-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
38+
stub_request(:any, /https:\/\/telemetry.*/)
39+
.to_return(status: 200, body: 'ok')
40+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
3941
.to_return(status: 200, body: splits_json)
42+
stub_request(:any, /https:\/\/events.*/)
43+
.to_return(status: 200, body: 'ok')
44+
sleep 1
4045
end
4146

4247
it 'validates the treatment is ON for correct attribute value' do
@@ -57,8 +62,13 @@
5762
let(:matching_negative_zero_attributes) { { age: -0 } }
5863

5964
before do
60-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
65+
stub_request(:any, /https:\/\/telemetry.*/)
66+
.to_return(status: 200, body: 'ok')
67+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
6168
.to_return(status: 200, body: zero_splits_json)
69+
stub_request(:any, /https:\/\/events.*/)
70+
.to_return(status: 200, body: 'ok')
71+
sleep 1
6272
end
6373

6474
it 'validates the treatment is ON for 0 and -0 attribute values' do
@@ -78,8 +88,13 @@
7888
let(:non_matching_negative_attributes) { { age: -10 } }
7989

8090
before do
81-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
91+
stub_request(:any, /https:\/\/telemetry.*/)
92+
.to_return(status: 200, body: 'ok')
93+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
8294
.to_return(status: 200, body: negative_splits_json)
95+
stub_request(:any, /https:\/\/events.*/)
96+
.to_return(status: 200, body: 'ok')
97+
sleep 1
8398
end
8499

85100
it 'validates the treatment is on for negative attribute value' do
@@ -100,8 +115,13 @@
100115
let(:non_matching_low_value_attributes) { { created: Time.parse('2016/03/31T23:59Z').to_i } }
101116

102117
before do
103-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
118+
stub_request(:any, /https:\/\/telemetry.*/)
119+
.to_return(status: 200, body: 'ok')
120+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
104121
.to_return(status: 200, body: date_splits_json)
122+
stub_request(:any, /https:\/\/events.*/)
123+
.to_return(status: 200, body: 'ok')
124+
sleep 1
105125
end
106126

107127
it 'validates the treatment is ON for correct number attribute value' do
@@ -116,6 +136,8 @@
116136
expect(subject.get_treatment(user, feature, non_matching_high_value_attributes)).to eq 'default'
117137
expect(subject.get_treatment(user, feature, missing_key_attributes)).to eq 'default'
118138
expect(subject.get_treatment(user, feature, nil_attributes)).to eq 'default'
139+
sleep 1
140+
subject.destroy()
119141
end
120142
end
121143
end

spec/engine/matchers/greater_than_or_equal_to_matcher_spec.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe SplitIoClient::GreaterThanOrEqualToMatcher do
66
subject do
7-
SplitIoClient::SplitFactory.new('test_api_key', logger: Logger.new('/dev/null'), streaming_enabled: false).client
7+
SplitIoClient::SplitFactory.new('test_api_key', {logger: Logger.new('/dev/null'), streaming_enabled: false, impressions_refresh_rate: 9999, impressions_mode: :none, features_refresh_rate: 9999, telemetry_refresh_rate: 99999}).client
88
end
99

1010
let(:date_splits_json) do
@@ -33,8 +33,12 @@
3333
let(:non_matching_value_attributes) { { age: 29 } }
3434

3535
before do
36-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
36+
stub_request(:any, /https:\/\/telemetry.*/)
37+
.to_return(status: 200, body: 'ok')
38+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
3739
.to_return(status: 200, body: splits_json)
40+
stub_request(:any, /https:\/\/events.*/)
41+
.to_return(status: 200, body: "", headers: {})
3842
end
3943

4044
it 'validates the treatment is ON for correct attribute value' do
@@ -55,8 +59,12 @@
5559
let(:non_matching_negative_attributes) { { age: -91 } }
5660

5761
before do
58-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
62+
stub_request(:any, /https:\/\/telemetry.*/)
63+
.to_return(status: 200, body: 'ok')
64+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
5965
.to_return(status: 200, body: negative_splits_json)
66+
stub_request(:any, /https:\/\/events.*/)
67+
.to_return(status: 200, body: "", headers: {})
6068
end
6169

6270
it 'validates the treatment is ON for correct negative attribute value' do
@@ -82,8 +90,12 @@
8290
let(:non_matching_attributes_2) { { created: Time.parse('2015/04/01T00:01Z').to_i } }
8391

8492
before do
85-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
93+
stub_request(:any, /https:\/\/telemetry.*/)
94+
.to_return(status: 200, body: 'ok')
95+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
8696
.to_return(status: 200, body: date_splits_json)
97+
stub_request(:any, /https:\/\/events.*/)
98+
.to_return(status: 200, body: "", headers: {})
8799
end
88100

89101
it 'validates the treatment is ON for correct attribute value' do
@@ -98,6 +110,8 @@
98110
expect(subject.get_treatment(user, feature, non_matching_attributes_2)).to eq 'default'
99111
expect(subject.get_treatment(user, feature, missing_key_attributes)).to eq 'default'
100112
expect(subject.get_treatment(user, feature, nil_attributes)).to eq 'default'
113+
sleep 1
114+
subject.destroy()
101115
end
102116
end
103117
end

spec/engine/matchers/less_than_or_equal_to_matcher_spec.rb

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe SplitIoClient::LessThanOrEqualToMatcher do
66
subject do
7-
SplitIoClient::SplitFactory.new('test_api_key', logger: Logger.new('/dev/null'), streaming_enabled: false).client
7+
SplitIoClient::SplitFactory.new('test_api_key', {logger: Logger.new('/dev/null'), streaming_enabled: false, impressions_refresh_rate: 9999, impressions_mode: :none, features_refresh_rate: 9999, telemetry_refresh_rate: 99999}).client
88
end
99

1010
let(:date_splits_json) do
@@ -35,8 +35,13 @@
3535
let(:non_matching_value_attributes) { { age: 31 } }
3636

3737
before do
38-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
38+
stub_request(:any, /https:\/\/telemetry.*/)
39+
.to_return(status: 200, body: 'ok')
40+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
3941
.to_return(status: 200, body: splits_json)
42+
stub_request(:any, /https:\/\/events.*/)
43+
.to_return(status: 200, body: "", headers: {})
44+
sleep 1
4045
end
4146

4247
it 'validates the treatment is ON for correct attribute value' do
@@ -57,8 +62,13 @@
5762
let(:non_matching_negative_attributes) { { age: -1 } }
5863

5964
before do
60-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
65+
stub_request(:any, /https:\/\/telemetry.*/)
66+
.to_return(status: 200, body: 'ok')
67+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
6168
.to_return(status: 200, body: negative_splits_json)
69+
stub_request(:any, /https:\/\/events.*/)
70+
.to_return(status: 200, body: "", headers: {})
71+
sleep 1
6272
end
6373

6474
it 'validates the treatment is ON for correct negative attribute value' do
@@ -81,8 +91,13 @@
8191
let(:non_matching_attributes_2) { { created: Time.parse('2017/04/01T00:01Z').to_i } }
8292

8393
before do
84-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
94+
stub_request(:any, /https:\/\/telemetry.*/)
95+
.to_return(status: 200, body: 'ok')
96+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
8597
.to_return(status: 200, body: date_splits_json)
98+
stub_request(:any, /https:\/\/events.*/)
99+
.to_return(status: 200, body: "", headers: {})
100+
sleep 1
86101
end
87102

88103
it 'validates the treatment is ON for correct attribute value' do
@@ -102,14 +117,21 @@
102117

103118
context 'wrongly formed date' do
104119
before do
105-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
120+
stub_request(:any, /https:\/\/telemetry.*/)
121+
.to_return(status: 200, body: 'ok')
122+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
106123
.to_return(status: 200, body: date_splits2_json)
124+
stub_request(:any, /https:\/\/events.*/)
125+
.to_return(status: 200, body: "", headers: {})
126+
sleep 1
107127
end
108128

109129
it 'validates the treatment is the default for wrongly formed date attribute' do
110130
subject.block_until_ready
111131
expect(subject.get_treatment(user, 'RUBY_isOnOrBeforeDateTimeWithAttributeValueThatDoesNotMatch', join: 'fer'))
112132
.to eq 'V1'
133+
sleep 1
134+
subject.destroy()
113135
end
114136
end
115137
end

spec/engine/matchers/whitelist_matcher_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe SplitIoClient::WhitelistMatcher do
66
subject do
7-
SplitIoClient::SplitFactory.new('test_api_key', logger: Logger.new('/dev/null'), streaming_enabled: false).client
7+
SplitIoClient::SplitFactory.new('test_api_key', {logger: Logger.new('/dev/null'), streaming_enabled: false, impressions_refresh_rate: 9999, impressions_mode: :none, features_refresh_rate: 9999, telemetry_refresh_rate: 99999}).client
88
end
99

1010
let(:splits_json) do
@@ -20,8 +20,12 @@
2020
let(:nil_attributes) { nil }
2121

2222
before do
23-
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
23+
stub_request(:any, /https:\/\/telemetry.*/)
24+
.to_return(status: 200, body: 'ok')
25+
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
2426
.to_return(status: 200, body: splits_json)
27+
stub_request(:any, /https:\/\/events.*/)
28+
.to_return(status: 200, body: "", headers: {})
2529
end
2630

2731
it 'validates the treatment is ON for correct attribute value' do
@@ -34,5 +38,7 @@
3438
expect(subject.get_treatment(user, feature, non_matching_value_attributes)).to eq 'default'
3539
expect(subject.get_treatment(user, feature, missing_key_attributes)).to eq 'default'
3640
expect(subject.get_treatment(user, feature, nil_attributes)).to eq 'default'
41+
sleep 1
42+
subject.destroy()
3743
end
3844
end

spec/engine/sync_manager_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
expect(a_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')).to have_been_made.once
8686

8787
expect(config.threads.size).to eq(11)
88+
config.threads.values.each { |thread| Thread.kill(thread) }
8889
end
8990
end
9091

@@ -104,6 +105,7 @@
104105
expect(a_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')).to have_been_made.once
105106

106107
expect(config.threads.size).to eq(8)
108+
config.threads.values.each { |thread| Thread.kill(thread) }
107109
end
108110
end
109111

@@ -125,6 +127,7 @@
125127

126128
sse_handler = sync_manager.instance_variable_get(:@sse_handler)
127129
expect(sse_handler.connected?).to eq(false)
130+
config.threads.values.each { |thread| Thread.kill(thread) }
128131
end
129132
end
130133

spec/engine/synchronizer_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@
217217
expect(a_request(:get, 'https://sdk.split.io/api/segmentChanges/segment3?since=111333')).to have_been_made.times(10)
218218
expect(a_request(:get, 'https://sdk.split.io/api/segmentChanges/segment3?since=111333&till=111555')).to have_been_made.once
219219
expect(a_request(:get, 'https://sdk.split.io/api/segmentChanges/segment3?since=111555&till=111555')).to have_been_made.once
220+
synchronizer.stop_periodic_fetch
221+
config.threads.values.each { |thread| Thread.kill(thread) }
220222
end
221223
end
222224

0 commit comments

Comments
 (0)