diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/analytics | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/analytics')
15 files changed, 76 insertions, 14 deletions
diff --git a/spec/lib/gitlab/analytics/cycle_analytics/base_query_builder_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/base_query_builder_spec.rb index 250e2f16aec..80d3f82b404 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/base_query_builder_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/base_query_builder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::BaseQueryBuilder do +RSpec.describe Gitlab::Analytics::CycleAnalytics::BaseQueryBuilder do let_it_be(:project) { create(:project, :empty_repo) } let_it_be(:mr1) { create(:merge_request, target_project: project, source_project: project, allow_broken: true, created_at: 3.months.ago) } let_it_be(:mr2) { create(:merge_request, target_project: project, source_project: project, allow_broken: true, created_at: 1.month.ago) } diff --git a/spec/lib/gitlab/analytics/cycle_analytics/median_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/median_spec.rb index 92ecec350ae..c1ea000eb7b 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/median_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/median_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::Median do +RSpec.describe Gitlab::Analytics::CycleAnalytics::Median do let_it_be(:project) { create(:project, :repository) } let(:query) { Project.joins(merge_requests: :metrics) } diff --git a/spec/lib/gitlab/analytics/cycle_analytics/records_fetcher_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/records_fetcher_spec.rb index e3429b0ca57..b8f9dde4291 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/records_fetcher_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/records_fetcher_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::RecordsFetcher do +RSpec.describe Gitlab::Analytics::CycleAnalytics::RecordsFetcher do around do |example| Timecop.freeze { example.run } end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start_spec.rb index 29c8d548754..fe390289ef6 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::CodeStageStart do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::CodeStageStart do let(:subject) { described_class.new({}) } let(:project) { create(:project) } diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_created_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_created_spec.rb index efdef91c5a2..5cc6b05407f 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_created_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_created_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::IssueCreated do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::IssueCreated do it_behaves_like 'cycle analytics event' end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_first_mentioned_in_commit_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_first_mentioned_in_commit_spec.rb index 50883e1c1e2..715ad5a8e7d 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_first_mentioned_in_commit_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_first_mentioned_in_commit_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::IssueFirstMentionedInCommit do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::IssueFirstMentionedInCommit do it_behaves_like 'cycle analytics event' end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end_spec.rb index 85062db370a..56241194f36 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::IssueStageEnd do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::IssueStageEnd do it_behaves_like 'cycle analytics event' end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_created_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_created_spec.rb index 7858b810661..f3202eab5bb 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_created_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_created_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestCreated do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestCreated do it_behaves_like 'cycle analytics event' end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_first_deployed_to_production_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_first_deployed_to_production_spec.rb index ba9d8be5a2c..03b0ccfae43 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_first_deployed_to_production_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_first_deployed_to_production_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestFirstDeployedToProduction do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestFirstDeployedToProduction do it_behaves_like 'cycle analytics event' end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_finished_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_finished_spec.rb index 8e83e10ef96..b0c003e6f2a 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_finished_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_finished_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestLastBuildFinished do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestLastBuildFinished do it_behaves_like 'cycle analytics event' end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_started_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_started_spec.rb index 9f6b430a320..8f9aaf6f463 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_started_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_last_build_started_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestLastBuildStarted do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestLastBuildStarted do it_behaves_like 'cycle analytics event' end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_merged_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_merged_spec.rb index ce2aa0a60db..f1d2ca9f36e 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_merged_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/merge_request_merged_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestMerged do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestMerged do it_behaves_like 'cycle analytics event' end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start_spec.rb index cb63139f0a8..3248af524bd 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::PlanStageStart do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::PlanStageStart do let(:subject) { described_class.new({}) } let(:project) { create(:project) } diff --git a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/stage_event_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/stage_event_spec.rb index b05faf5d813..6fc658ecade 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/stage_events/stage_event_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/stage_events/stage_event_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Analytics::CycleAnalytics::StageEvents::StageEvent do +RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::StageEvent do let(:instance) { described_class.new({}) } it { expect(described_class).to respond_to(:name) } diff --git a/spec/lib/gitlab/analytics/unique_visits_spec.rb b/spec/lib/gitlab/analytics/unique_visits_spec.rb new file mode 100644 index 00000000000..ff3623a3a71 --- /dev/null +++ b/spec/lib/gitlab/analytics/unique_visits_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Analytics::UniqueVisits, :clean_gitlab_redis_shared_state do + let(:unique_visits) { Gitlab::Analytics::UniqueVisits.new } + let(:target1_id) { 'g_analytics_contribution' } + let(:target2_id) { 'g_analytics_insights' } + let(:target3_id) { 'g_analytics_issues' } + let(:visitor1_id) { 'dfb9d2d2-f56c-4c77-8aeb-6cddc4a1f857' } + let(:visitor2_id) { '1dd9afb2-a3ee-4de1-8ae3-a405579c8584' } + + around do |example| + # We need to freeze to a reference time + # because visits are grouped by the week number in the year + # Without freezing the time, the test may behave inconsistently + # depending on which day of the week test is run. + reference_time = Time.utc(2020, 6, 1) + Timecop.freeze(reference_time) { example.run } + end + + describe '#track_visit' do + it 'tracks the unique weekly visits for targets' do + unique_visits.track_visit(visitor1_id, target1_id, 7.days.ago) + unique_visits.track_visit(visitor1_id, target1_id, 7.days.ago) + unique_visits.track_visit(visitor2_id, target1_id, 7.days.ago) + + unique_visits.track_visit(visitor2_id, target2_id, 7.days.ago) + 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) + + expect(unique_visits.weekly_unique_visits_for_target(target2_id, week_of: 15.days.ago)).to eq(1) + + expect(unique_visits.weekly_unique_visits_for_target(target3_id)).to eq(0) + + 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) + end + + it 'sets the keys in Redis to expire automatically after 28 days' 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) + end + end + end + + it 'raises an error if an invalid target id is given' do + invalid_target_id = "x_invalid" + + expect do + unique_visits.track_visit(visitor1_id, invalid_target_id) + end.to raise_error("Invalid target id #{invalid_target_id}") + end + end +end |