Commit 526e383c authored by Stan Hu's avatar Stan Hu

Merge branch 'aa-speed-up-usage-data-specs' into 'master'

Speed up usage data specs

See merge request gitlab-org/gitlab!38697
parents f53bd910 98465b76
......@@ -13,8 +13,14 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
describe '.uncached_data' do
describe '.usage_activity_by_stage' do
it 'includes usage_activity_by_stage data' do
expect(described_class.uncached_data).to include(:usage_activity_by_stage)
expect(described_class.uncached_data).to include(:usage_activity_by_stage_monthly)
uncached_data = described_class.uncached_data
expect(uncached_data).to include(:usage_activity_by_stage)
expect(uncached_data).to include(:usage_activity_by_stage_monthly)
expect(uncached_data[:usage_activity_by_stage])
.to include(:configure, :create, :manage, :monitor, :plan, :release, :verify)
expect(uncached_data[:usage_activity_by_stage_monthly])
.to include(:configure, :create, :manage, :monitor, :plan, :release, :verify)
end
it 'clears memoized values' do
......@@ -30,7 +36,27 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
described_class.uncached_data
end
context 'for configure' do
it 'merge_requests_users is included only in montly counters' do
uncached_data = described_class.uncached_data
expect(uncached_data[:usage_activity_by_stage][:create])
.not_to include(:merge_requests_users)
expect(uncached_data[:usage_activity_by_stage_monthly][:create])
.to include(:merge_requests_users)
end
end
it 'ensures recorded_at is set before any other usage data calculation' do
%i(alt_usage_data redis_usage_data distinct_count count).each do |method|
expect(described_class).not_to receive(method)
end
expect(described_class).to receive(:recorded_at).and_raise(Exception.new('Stopped calculating recorded_at'))
expect { described_class.uncached_data }.to raise_error('Stopped calculating recorded_at')
end
end
describe '.usage_activity_by_stage_configure' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user)
......@@ -50,7 +76,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:cluster, :management_project)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:configure]).to include(
expect(described_class.usage_activity_by_stage_configure({})).to include(
clusters_applications_cert_managers: 2,
clusters_applications_helm: 2,
clusters_applications_ingress: 2,
......@@ -68,7 +94,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
project_clusters_disabled: 2,
project_clusters_enabled: 10
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:configure]).to include(
expect(described_class.usage_activity_by_stage_configure(described_class.last_28_days_time_period)).to include(
clusters_applications_cert_managers: 1,
clusters_applications_helm: 1,
clusters_applications_ingress: 1,
......@@ -89,21 +115,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
context 'for create' do
it 'include usage_activity_by_stage data' do
expect(described_class.uncached_data[:usage_activity_by_stage][:create])
.not_to include(
:merge_requests_users
)
end
it 'includes monthly usage_activity_by_stage data' do
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create])
.to include(
:merge_requests_users
)
end
describe 'usage_activity_by_stage_create' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user)
......@@ -118,7 +130,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:snippet, author: user)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:create]).to include(
expect(described_class.usage_activity_by_stage_create({})).to include(
deploy_keys: 2,
keys: 2,
merge_requests: 2,
......@@ -127,7 +139,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
remote_mirrors: 2,
snippets: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create]).to include(
expect(described_class.usage_activity_by_stage_create(described_class.last_28_days_time_period)).to include(
deploy_keys: 1,
keys: 1,
merge_requests: 1,
......@@ -139,7 +151,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
context 'for manage' do
describe 'usage_activity_by_stage_manage' do
it 'includes accurate usage_activity_by_stage data' do
stub_config(
omniauth:
......@@ -152,16 +164,16 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:group_member, user: user)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to include(
expect(described_class.usage_activity_by_stage_manage({})).to include(
events: 2,
groups: 2,
users_created: 6,
users_created: 4,
omniauth_providers: ['google_oauth2']
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to include(
expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
events: 1,
groups: 1,
users_created: 4,
users_created: 2,
omniauth_providers: ['google_oauth2']
)
end
......@@ -175,7 +187,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
context 'for monitor' do
describe 'usage_activity_by_stage_monitor' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user, dashboard: 'operations')
......@@ -184,12 +196,12 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:clusters_applications_prometheus, :installed, cluster: cluster)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:monitor]).to include(
expect(described_class.usage_activity_by_stage_monitor({})).to include(
clusters: 2,
clusters_applications_prometheus: 2,
operations_dashboard_default_dashboard: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:monitor]).to include(
expect(described_class.usage_activity_by_stage_monitor(described_class.last_28_days_time_period)).to include(
clusters: 1,
clusters_applications_prometheus: 1,
operations_dashboard_default_dashboard: 1
......@@ -197,7 +209,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
context 'for plan' do
describe 'usage_activity_by_stage_plan' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user)
......@@ -208,7 +220,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:todo, project: project, target: issue, author: user)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:plan]).to include(
expect(described_class.usage_activity_by_stage_plan({})).to include(
issues: 3,
notes: 2,
projects: 2,
......@@ -216,7 +228,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
service_desk_enabled_projects: 2,
service_desk_issues: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:plan]).to include(
expect(described_class.usage_activity_by_stage_plan(described_class.last_28_days_time_period)).to include(
issues: 2,
notes: 1,
projects: 1,
......@@ -227,7 +239,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
context 'for release' do
describe 'usage_activity_by_stage_release' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user)
......@@ -236,13 +248,13 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:deployment, :success, user: user)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:release]).to include(
expect(described_class.usage_activity_by_stage_release({})).to include(
deployments: 2,
failed_deployments: 2,
releases: 2,
successful_deployments: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:release]).to include(
expect(described_class.usage_activity_by_stage_release(described_class.last_28_days_time_period)).to include(
deployments: 1,
failed_deployments: 1,
releases: 1,
......@@ -251,7 +263,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
context 'for verify' do
describe 'usage_activity_by_stage_verify' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user)
......@@ -265,7 +277,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:clusters_applications_runner, :installed)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:verify]).to include(
expect(described_class.usage_activity_by_stage_verify({})).to include(
ci_builds: 2,
ci_external_pipelines: 2,
ci_internal_pipelines: 2,
......@@ -276,7 +288,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
ci_triggers: 2,
clusters_applications_runner: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:verify]).to include(
expect(described_class.usage_activity_by_stage_verify(described_class.last_28_days_time_period)).to include(
ci_builds: 1,
ci_external_pipelines: 1,
ci_internal_pipelines: 1,
......@@ -289,17 +301,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
)
end
end
end
it 'ensures recorded_at is set before any other usage data calculation' do
%i(alt_usage_data redis_usage_data distinct_count count).each do |method|
expect(described_class).not_to receive(method)
end
expect(described_class).to receive(:recorded_at).and_raise(Exception.new('Stopped calculating recorded_at'))
expect { described_class.uncached_data }.to raise_error('Stopped calculating recorded_at')
end
end
describe '.data' do
let!(:ud) { build(:usage_data) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment