diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-23 15:00:18 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-23 15:00:18 +0000 |
commit | 6ce82deda34e8af9d07cf7dfff0057f33b9e6187 (patch) | |
tree | e88b7ca57376e83556c7a651d61dbe8ba09440b5 /spec/lib/gitlab/usage_data_counters | |
parent | 3d62fe7ad9b32c2e68d253d0b2bd178215c65fa5 (diff) | |
download | gitlab-ce-6ce82deda34e8af9d07cf7dfff0057f33b9e6187.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-ee
Diffstat (limited to 'spec/lib/gitlab/usage_data_counters')
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb index 70ee9871486..b6a60c09d3d 100644 --- a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb @@ -283,6 +283,50 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s context 'when no slot is set' do it { expect(described_class.unique_events(event_names: [no_slot], start_date: 7.days.ago, end_date: Date.current)).to eq(1) } end + + context 'when data crosses into new year' do + it 'does not raise error' do + expect { described_class.unique_events(event_names: [weekly_event], start_date: DateTime.parse('2020-12-26'), end_date: DateTime.parse('2021-02-01')) } + .not_to raise_error + end + end + end + end + + describe '.weekly_redis_keys' do + using RSpec::Parameterized::TableSyntax + + let(:weekly_event) { 'g_compliance_dashboard' } + let(:redis_event) { described_class.send(:event_for, weekly_event) } + + subject(:weekly_redis_keys) { described_class.send(:weekly_redis_keys, events: [redis_event], start_date: DateTime.parse(start_date), end_date: DateTime.parse(end_date)) } + + where(:start_date, :end_date, :keys) do + '2020-12-21' | '2020-12-21' | [] + '2020-12-21' | '2020-12-20' | [] + '2020-12-21' | '2020-11-21' | [] + '2021-01-01' | '2020-12-28' | [] + '2020-12-21' | '2020-12-28' | ['g_{compliance}_dashboard-2020-52'] + '2020-12-21' | '2021-01-01' | ['g_{compliance}_dashboard-2020-52'] + '2020-12-27' | '2021-01-01' | ['g_{compliance}_dashboard-2020-52'] + '2020-12-26' | '2021-01-04' | ['g_{compliance}_dashboard-2020-52', 'g_{compliance}_dashboard-2020-53'] + '2020-12-26' | '2021-01-11' | ['g_{compliance}_dashboard-2020-52', 'g_{compliance}_dashboard-2020-53', 'g_{compliance}_dashboard-2021-01'] + '2020-12-26' | '2021-01-17' | ['g_{compliance}_dashboard-2020-52', 'g_{compliance}_dashboard-2020-53', 'g_{compliance}_dashboard-2021-01'] + '2020-12-26' | '2021-01-18' | ['g_{compliance}_dashboard-2020-52', 'g_{compliance}_dashboard-2020-53', 'g_{compliance}_dashboard-2021-01', 'g_{compliance}_dashboard-2021-02'] + end + + with_them do + it "returns the correct keys" do + expect(subject).to match(keys) + end + end + + it 'returns 1 key for last for week' do + expect(described_class.send(:weekly_redis_keys, events: [redis_event], start_date: 7.days.ago.to_date, end_date: Date.current).size).to eq 1 + end + + it 'returns 4 key for last for weeks' do + expect(described_class.send(:weekly_redis_keys, events: [redis_event], start_date: 4.weeks.ago.to_date, end_date: Date.current).size).to eq 4 end end |