diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/lib/gitlab/analytics/unique_visits_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/lib/gitlab/analytics/unique_visits_spec.rb')
-rw-r--r-- | spec/lib/gitlab/analytics/unique_visits_spec.rb | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/spec/lib/gitlab/analytics/unique_visits_spec.rb b/spec/lib/gitlab/analytics/unique_visits_spec.rb index ff3623a3a71..1432c9ac58f 100644 --- a/spec/lib/gitlab/analytics/unique_visits_spec.rb +++ b/spec/lib/gitlab/analytics/unique_visits_spec.rb @@ -7,8 +7,11 @@ RSpec.describe Gitlab::Analytics::UniqueVisits, :clean_gitlab_redis_shared_state let(:target1_id) { 'g_analytics_contribution' } let(:target2_id) { 'g_analytics_insights' } let(:target3_id) { 'g_analytics_issues' } + let(:target4_id) { 'g_compliance_dashboard' } + let(:target5_id) { 'i_compliance_credential_inventory' } let(:visitor1_id) { 'dfb9d2d2-f56c-4c77-8aeb-6cddc4a1f857' } let(:visitor2_id) { '1dd9afb2-a3ee-4de1-8ae3-a405579c8584' } + let(:visitor3_id) { '34rfjuuy-ce56-sa35-ds34-dfer567dfrf2' } around do |example| # We need to freeze to a reference time @@ -29,24 +32,40 @@ RSpec.describe Gitlab::Analytics::UniqueVisits, :clean_gitlab_redis_shared_state unique_visits.track_visit(visitor1_id, target2_id, 8.days.ago) unique_visits.track_visit(visitor1_id, target2_id, 15.days.ago) - expect(unique_visits.weekly_unique_visits_for_target(target1_id)).to eq(2) - expect(unique_visits.weekly_unique_visits_for_target(target2_id)).to eq(1) + unique_visits.track_visit(visitor3_id, target4_id, 7.days.ago) - expect(unique_visits.weekly_unique_visits_for_target(target2_id, week_of: 15.days.ago)).to eq(1) + unique_visits.track_visit(visitor3_id, target5_id, 15.days.ago) + unique_visits.track_visit(visitor2_id, target5_id, 15.days.ago) - expect(unique_visits.weekly_unique_visits_for_target(target3_id)).to eq(0) + expect(unique_visits.unique_visits_for(targets: target1_id)).to eq(2) + expect(unique_visits.unique_visits_for(targets: target2_id)).to eq(1) + expect(unique_visits.unique_visits_for(targets: target4_id)).to eq(1) - expect(unique_visits.weekly_unique_visits_for_any_target).to eq(2) - expect(unique_visits.weekly_unique_visits_for_any_target(week_of: 15.days.ago)).to eq(1) - expect(unique_visits.weekly_unique_visits_for_any_target(week_of: 30.days.ago)).to eq(0) + expect(unique_visits.unique_visits_for(targets: target2_id, start_date: 15.days.ago)).to eq(1) + + expect(unique_visits.unique_visits_for(targets: target3_id)).to eq(0) + + expect(unique_visits.unique_visits_for(targets: target5_id, start_date: 15.days.ago)).to eq(2) + + expect(unique_visits.unique_visits_for(targets: :analytics)).to eq(2) + expect(unique_visits.unique_visits_for(targets: :analytics, start_date: 15.days.ago)).to eq(1) + expect(unique_visits.unique_visits_for(targets: :analytics, start_date: 30.days.ago)).to eq(0) + + expect(unique_visits.unique_visits_for(targets: :analytics, start_date: 4.weeks.ago, end_date: Date.current)).to eq(2) + + expect(unique_visits.unique_visits_for(targets: :compliance)).to eq(1) + expect(unique_visits.unique_visits_for(targets: :compliance, start_date: 15.days.ago)).to eq(2) + expect(unique_visits.unique_visits_for(targets: :compliance, start_date: 30.days.ago)).to eq(0) + + expect(unique_visits.unique_visits_for(targets: :compliance, start_date: 4.weeks.ago, end_date: Date.current)).to eq(2) end - it 'sets the keys in Redis to expire automatically after 28 days' do + it 'sets the keys in Redis to expire automatically after 12 weeks' do unique_visits.track_visit(visitor1_id, target1_id) Gitlab::Redis::SharedState.with do |redis| - redis.scan_each(match: "#{target1_id}-*").each do |key| - expect(redis.ttl(key)).to be_within(5.seconds).of(28.days) + redis.scan_each(match: "{#{target1_id}}-*").each do |key| + expect(redis.ttl(key)).to be_within(5.seconds).of(12.weeks) end end end @@ -56,7 +75,7 @@ RSpec.describe Gitlab::Analytics::UniqueVisits, :clean_gitlab_redis_shared_state expect do unique_visits.track_visit(visitor1_id, invalid_target_id) - end.to raise_error("Invalid target id #{invalid_target_id}") + end.to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownEvent) end end end |