Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2024-01-05 00:07:37 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2024-01-05 00:07:37 +0300
commit808b8561f4e75b2db7c7e94a6c7651efb546048b (patch)
tree2cb7546939b56fef3a73a52dd8790de55f0fc0e4 /spec/lib
parentcc514c362bcd4b657bf6a6d1d37f5305952df363 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/atlassian/jira_connect/client_spec.rb6
-rw-r--r--spec/lib/atlassian/jira_connect/serializers/pull_request_entity_spec.rb6
-rw-r--r--spec/lib/backup/repositories_spec.rb8
-rw-r--r--spec/lib/banzai/filter/custom_emoji_filter_spec.rb4
-rw-r--r--spec/lib/banzai/filter/issuable_reference_expansion_filter_spec.rb16
-rw-r--r--spec/lib/banzai/filter/references/alert_reference_filter_spec.rb10
-rw-r--r--spec/lib/banzai/filter/references/commit_reference_filter_spec.rb10
-rw-r--r--spec/lib/banzai/filter/references/design_reference_filter_spec.rb4
-rw-r--r--spec/lib/banzai/filter/references/external_issue_reference_filter_spec.rb4
-rw-r--r--spec/lib/banzai/filter/references/issue_reference_filter_spec.rb4
-rw-r--r--spec/lib/banzai/filter/references/label_reference_filter_spec.rb4
-rw-r--r--spec/lib/banzai/filter/references/merge_request_reference_filter_spec.rb4
-rw-r--r--spec/lib/banzai/filter/references/project_reference_filter_spec.rb8
-rw-r--r--spec/lib/banzai/filter/references/reference_cache_spec.rb10
-rw-r--r--spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb10
-rw-r--r--spec/lib/banzai/filter/references/work_item_reference_filter_spec.rb4
-rw-r--r--spec/lib/banzai/issuable_extractor_spec.rb4
-rw-r--r--spec/lib/banzai/reference_parser/snippet_parser_spec.rb4
-rw-r--r--spec/lib/gitlab/data_builder/pipeline_spec.rb8
-rw-r--r--spec/lib/gitlab/git_access_spec.rb4
-rw-r--r--spec/lib/gitlab/tracking/destinations/database_events_snowplow_spec.rb140
-rw-r--r--spec/lib/gitlab/tracking_spec.rb32
22 files changed, 62 insertions, 242 deletions
diff --git a/spec/lib/atlassian/jira_connect/client_spec.rb b/spec/lib/atlassian/jira_connect/client_spec.rb
index a692d76da77..e1159b9fab2 100644
--- a/spec/lib/atlassian/jira_connect/client_spec.rb
+++ b/spec/lib/atlassian/jira_connect/client_spec.rb
@@ -433,16 +433,16 @@ RSpec.describe Atlassian::JiraConnect::Client, feature_category: :integrations d
end
it 'avoids N+1 database queries' do
- control_count = ActiveRecord::QueryRecorder.new do
+ control = ActiveRecord::QueryRecorder.new do
subject.send(:store_dev_info, project: project, merge_requests: merge_requests)
- end.count
+ end
merge_requests << create(:merge_request, :unique_branches, source_project: project)
expect do
subject.send(:store_dev_info, project: project,
merge_requests: merge_requests)
- end.not_to exceed_query_limit(control_count)
+ end.not_to exceed_query_limit(control)
end
end
diff --git a/spec/lib/atlassian/jira_connect/serializers/pull_request_entity_spec.rb b/spec/lib/atlassian/jira_connect/serializers/pull_request_entity_spec.rb
index 0ed320e863c..15cb4994d46 100644
--- a/spec/lib/atlassian/jira_connect/serializers/pull_request_entity_spec.rb
+++ b/spec/lib/atlassian/jira_connect/serializers/pull_request_entity_spec.rb
@@ -24,9 +24,9 @@ RSpec.describe Atlassian::JiraConnect::Serializers::PullRequestEntity, feature_c
subject { described_class.represent(merge_requests, user_notes_count: user_notes_count).as_json }
it 'avoids N+1 database queries' do
- control_count = ActiveRecord::QueryRecorder.new do
+ control = ActiveRecord::QueryRecorder.new do
described_class.represent(merge_requests, user_notes_count: user_notes_count)
- end.count
+ end
merge_requests << create(:merge_request, :unique_branches)
@@ -35,7 +35,7 @@ RSpec.describe Atlassian::JiraConnect::Serializers::PullRequestEntity, feature_c
records: merge_requests, associations: { merge_request_reviewers: :reviewer }
).call
- expect { subject }.not_to exceed_query_limit(control_count)
+ expect { subject }.not_to exceed_query_limit(control)
end
it 'uses counts from user_notes_count' do
diff --git a/spec/lib/backup/repositories_spec.rb b/spec/lib/backup/repositories_spec.rb
index 024f6c5db96..679be62393e 100644
--- a/spec/lib/backup/repositories_spec.rb
+++ b/spec/lib/backup/repositories_spec.rb
@@ -68,20 +68,20 @@ RSpec.describe Backup::Repositories, feature_category: :backup_restore do
end
it 'avoids N+1 database queries' do
- control_count = ActiveRecord::QueryRecorder.new do
+ control = ActiveRecord::QueryRecorder.new do
subject.dump(destination, backup_id)
- end.count
+ end
create_list(:project, 2, :repository)
create_list(:snippet, 2, :repository)
- # Number of expected queries are 2 more than control_count
+ # Number of expected queries are 2 more than control.count
# to account for the queries for project.design_management_repository
# for each project.
# We are using 2 projects here.
expect do
subject.dump(destination, backup_id)
- end.not_to exceed_query_limit(control_count + 2)
+ end.not_to exceed_query_limit(control).with_threshold(2)
end
describe 'storages' do
diff --git a/spec/lib/banzai/filter/custom_emoji_filter_spec.rb b/spec/lib/banzai/filter/custom_emoji_filter_spec.rb
index 4fc9d9dd4f6..701a45aa54d 100644
--- a/spec/lib/banzai/filter/custom_emoji_filter_spec.rb
+++ b/spec/lib/banzai/filter/custom_emoji_filter_spec.rb
@@ -47,13 +47,13 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter, feature_category: :team_planni
it 'does not do N+1 query' do
create(:custom_emoji, name: 'party-parrot', group: group)
- control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
filter('<p>:tanuki:</p>')
end
expect do
filter('<p>:tanuki:</p> <p>:party-parrot:</p>')
- end.not_to exceed_all_query_limit(control_count.count)
+ end.not_to exceed_all_query_limit(control)
end
it 'uses custom emoji from ancestor group' do
diff --git a/spec/lib/banzai/filter/issuable_reference_expansion_filter_spec.rb b/spec/lib/banzai/filter/issuable_reference_expansion_filter_spec.rb
index 06bb0edc92c..d14f218763f 100644
--- a/spec/lib/banzai/filter/issuable_reference_expansion_filter_spec.rb
+++ b/spec/lib/banzai/filter/issuable_reference_expansion_filter_spec.rb
@@ -259,15 +259,15 @@ RSpec.describe Banzai::Filter::IssuableReferenceExpansionFilter, feature_categor
# warm up
filter(link, context)
- control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
filter(link, context)
- end.count
+ end
- expect(control_count).to eq 12
+ expect(control.count).to eq 12
expect do
filter("#{link} #{link2}", context)
- end.not_to exceed_all_query_limit(control_count)
+ end.not_to exceed_all_query_limit(control)
end
end
end
@@ -419,15 +419,15 @@ RSpec.describe Banzai::Filter::IssuableReferenceExpansionFilter, feature_categor
# warm up
filter(link, context)
- control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
filter(link, context)
- end.count
+ end
- expect(control_count).to eq 10
+ expect(control.count).to eq 10
expect do
filter("#{link} #{link2}", context)
- end.not_to exceed_all_query_limit(control_count)
+ end.not_to exceed_all_query_limit(control)
end
end
end
diff --git a/spec/lib/banzai/filter/references/alert_reference_filter_spec.rb b/spec/lib/banzai/filter/references/alert_reference_filter_spec.rb
index 9a2e68aaae0..0bdd64c360d 100644
--- a/spec/lib/banzai/filter/references/alert_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/alert_reference_filter_spec.rb
@@ -230,11 +230,11 @@ RSpec.describe Banzai::Filter::References::AlertReferenceFilter, feature_categor
it 'does not have N+1 per multiple references per project', :use_sql_query_cache do
markdown = alert_reference.to_s
- max_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
reference_filter(markdown)
- end.count
+ end
- expect(max_count).to eq 1
+ expect(control.count).to eq 1
markdown = "#{alert_reference} ^alert#2 ^alert#3 ^alert#4 #{alert2_reference}"
@@ -248,11 +248,9 @@ RSpec.describe Banzai::Filter::References::AlertReferenceFilter, feature_categor
# 1x2 for alerts in each project
# Total == 7
# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/330359
- max_count += 6
-
expect do
reference_filter(markdown)
- end.not_to exceed_all_query_limit(max_count)
+ end.not_to exceed_all_query_limit(control).with_threshold(6)
end
end
end
diff --git a/spec/lib/banzai/filter/references/commit_reference_filter_spec.rb b/spec/lib/banzai/filter/references/commit_reference_filter_spec.rb
index 35a3f20f7b7..730554857df 100644
--- a/spec/lib/banzai/filter/references/commit_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/commit_reference_filter_spec.rb
@@ -283,11 +283,11 @@ RSpec.describe Banzai::Filter::References::CommitReferenceFilter, feature_catego
it 'does not have N+1 per multiple references per project', :use_sql_query_cache do
markdown = commit_reference.to_s
- max_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
reference_filter(markdown)
- end.count
+ end
- expect(max_count).to eq 0
+ expect(control.count).to eq 0
markdown = "#{commit_reference} 8b95f2f1 8b95f2f2 8b95f2f3 #{commit2_reference} #{commit3_reference}"
@@ -298,11 +298,9 @@ RSpec.describe Banzai::Filter::References::CommitReferenceFilter, feature_catego
# 1 for loading the namespaces associated to the project
# 1 for loading the routes associated with the namespace
# Total = 5
- max_count += 5
-
expect do
reference_filter(markdown)
- end.not_to exceed_all_query_limit(max_count)
+ end.not_to exceed_all_query_limit(control).with_threshold(5)
end
end
end
diff --git a/spec/lib/banzai/filter/references/design_reference_filter_spec.rb b/spec/lib/banzai/filter/references/design_reference_filter_spec.rb
index fd03d7c0d27..678d6619101 100644
--- a/spec/lib/banzai/filter/references/design_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/design_reference_filter_spec.rb
@@ -240,7 +240,7 @@ RSpec.describe Banzai::Filter::References::DesignReferenceFilter, feature_catego
* #1[not a valid reference.gif]
MD
- baseline = ActiveRecord::QueryRecorder.new { process(one_ref_per_project) }
+ control = ActiveRecord::QueryRecorder.new { process(one_ref_per_project) }
# each project mentioned requires 2 queries:
#
@@ -253,7 +253,7 @@ RSpec.describe Banzai::Filter::References::DesignReferenceFilter, feature_catego
# In addition there is a 1 query overhead for all the projects at the
# start. Currently, the baseline for 2 projects is `2 * 2 + 1 = 5` queries
#
- expect { process(multiple_references) }.not_to exceed_query_limit(baseline.count)
+ expect { process(multiple_references) }.not_to exceed_query_limit(control)
end
end
diff --git a/spec/lib/banzai/filter/references/external_issue_reference_filter_spec.rb b/spec/lib/banzai/filter/references/external_issue_reference_filter_spec.rb
index 823f006c98a..acc59c85cbf 100644
--- a/spec/lib/banzai/filter/references/external_issue_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/external_issue_reference_filter_spec.rb
@@ -338,9 +338,9 @@ RSpec.describe Banzai::Filter::References::ExternalIssueReferenceFilter, feature
single_reference = "External Issue #{issue1.to_reference}"
multiple_references = "External Issues #{issue1.to_reference} and #{issue2.to_reference}"
- control_count = ActiveRecord::QueryRecorder.new { reference_filter(single_reference).to_html }.count
+ control = ActiveRecord::QueryRecorder.new { reference_filter(single_reference).to_html }
- expect { reference_filter(multiple_references).to_html }.not_to exceed_query_limit(control_count)
+ expect { reference_filter(multiple_references).to_html }.not_to exceed_query_limit(control)
end
end
end
diff --git a/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb
index d16188e99a3..fd947e3e9cb 100644
--- a/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb
@@ -41,9 +41,9 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter, feature_categor
single_reference = "Issue #{issue.to_reference}"
multiple_references = "Issues #{issue.to_reference} and #{another_issue.to_reference}"
- control_count = ActiveRecord::QueryRecorder.new { reference_filter(single_reference).to_html }.count
+ control = ActiveRecord::QueryRecorder.new { reference_filter(single_reference).to_html }
- expect { reference_filter(multiple_references).to_html }.not_to exceed_query_limit(control_count)
+ expect { reference_filter(multiple_references).to_html }.not_to exceed_query_limit(control)
end
end
diff --git a/spec/lib/banzai/filter/references/label_reference_filter_spec.rb b/spec/lib/banzai/filter/references/label_reference_filter_spec.rb
index 81b08a4c516..bcc256813c9 100644
--- a/spec/lib/banzai/filter/references/label_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/label_reference_filter_spec.rb
@@ -35,13 +35,13 @@ RSpec.describe Banzai::Filter::References::LabelReferenceFilter, feature_categor
# Run this once to establish a baseline
reference_filter("Label #{reference}")
- control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
reference_filter("Label #{reference}")
end
labels_markdown = Array.new(10, "Label #{reference}").join('\n')
- expect { reference_filter(labels_markdown) }.not_to exceed_all_query_limit(control_count.count)
+ expect { reference_filter(labels_markdown) }.not_to exceed_all_query_limit(control)
end
it 'includes a data-project attribute' do
diff --git a/spec/lib/banzai/filter/references/merge_request_reference_filter_spec.rb b/spec/lib/banzai/filter/references/merge_request_reference_filter_spec.rb
index ccc8478c7d8..e3036993f7b 100644
--- a/spec/lib/banzai/filter/references/merge_request_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/merge_request_reference_filter_spec.rb
@@ -26,9 +26,9 @@ RSpec.describe Banzai::Filter::References::MergeRequestReferenceFilter, feature_
single_reference = "Merge request #{merge.to_reference}"
multiple_references = "Merge requests #{merge.to_reference} and #{another_merge.to_reference}"
- control_count = ActiveRecord::QueryRecorder.new { reference_filter(single_reference).to_html }.count
+ control = ActiveRecord::QueryRecorder.new { reference_filter(single_reference).to_html }
- expect { reference_filter(multiple_references).to_html }.not_to exceed_query_limit(control_count)
+ expect { reference_filter(multiple_references).to_html }.not_to exceed_query_limit(control)
end
end
diff --git a/spec/lib/banzai/filter/references/project_reference_filter_spec.rb b/spec/lib/banzai/filter/references/project_reference_filter_spec.rb
index c55fff78756..12af94507b6 100644
--- a/spec/lib/banzai/filter/references/project_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/project_reference_filter_spec.rb
@@ -115,17 +115,17 @@ RSpec.describe Banzai::Filter::References::ProjectReferenceFilter, feature_categ
# warm up first
reference_filter(markdown)
- max_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
reference_filter(markdown)
- end.count
+ end
- expect(max_count).to eq 2
+ expect(control.count).to eq 2
markdown = "#{normal_project_reference} #{invalidate_reference(normal_project_reference)} #{group_project_reference} #{nested_project_reference}"
expect do
reference_filter(markdown)
- end.not_to exceed_all_query_limit(max_count)
+ end.not_to exceed_all_query_limit(control)
end
end
end
diff --git a/spec/lib/banzai/filter/references/reference_cache_spec.rb b/spec/lib/banzai/filter/references/reference_cache_spec.rb
index 04877931610..b4d9a08e4c6 100644
--- a/spec/lib/banzai/filter/references/reference_cache_spec.rb
+++ b/spec/lib/banzai/filter/references/reference_cache_spec.rb
@@ -70,13 +70,13 @@ RSpec.describe Banzai::Filter::References::ReferenceCache, feature_category: :te
filter_single = filter_class.new(doc_single, project: project)
cache_single = described_class.new(filter_single, { project: project }, {})
- control_count = ActiveRecord::QueryRecorder.new do
+ control = ActiveRecord::QueryRecorder.new do
cache_single.load_references_per_parent(filter_single.nodes)
cache_single.load_parent_per_reference
cache_single.load_records_per_parent
- end.count
+ end
- expect(control_count).to eq 3
+ expect(control.count).to eq 3
# Since this is an issue filter that is not batching issue queries
# across projects, we have to account for that.
# 1 for for routes to find routes.source_id of projects matching paths
@@ -88,13 +88,11 @@ RSpec.describe Banzai::Filter::References::ReferenceCache, feature_category: :te
# 1x2 for groups
# 1x2 for work_item_types
# Total = 11
- max_count = control_count + 8
-
expect do
cache.load_references_per_parent(filter.nodes)
cache.load_parent_per_reference
cache.load_records_per_parent
- end.not_to exceed_query_limit(max_count)
+ end.not_to exceed_query_limit(control).with_threshold(8)
end
end
diff --git a/spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb b/spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb
index 00eac7262f4..51c5551dda8 100644
--- a/spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/snippet_reference_filter_spec.rb
@@ -229,11 +229,11 @@ RSpec.describe Banzai::Filter::References::SnippetReferenceFilter, feature_categ
it 'does not have N+1 per multiple references per project', :use_sql_query_cache do
markdown = "#{reference} $9999990"
- control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
reference_filter(markdown)
- end.count
+ end
- expect(control_count).to eq 1
+ expect(control.count).to eq 1
markdown = "#{reference} $9999990 $9999991 $9999992 $9999993 #{reference2} something/cool$12"
@@ -247,11 +247,9 @@ RSpec.describe Banzai::Filter::References::SnippetReferenceFilter, feature_categ
# 1x2 for snippets in each project == 2
# Total = 7
# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/330359
- max_count = control_count + 6
-
expect do
reference_filter(markdown)
- end.not_to exceed_all_query_limit(max_count)
+ end.not_to exceed_all_query_limit(control).with_threshold(6)
end
end
end
diff --git a/spec/lib/banzai/filter/references/work_item_reference_filter_spec.rb b/spec/lib/banzai/filter/references/work_item_reference_filter_spec.rb
index e59e53891bf..cf245ccc72a 100644
--- a/spec/lib/banzai/filter/references/work_item_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/work_item_reference_filter_spec.rb
@@ -306,9 +306,9 @@ RSpec.describe Banzai::Filter::References::WorkItemReferenceFilter, feature_cate
single_reference = "Work item #{work_item.to_reference}"
multiple_references = "Work items #{work_item.to_reference} and #{another_work_item.to_reference}"
- control_count = ActiveRecord::QueryRecorder.new { reference_filter(single_reference).to_html }.count
+ control = ActiveRecord::QueryRecorder.new { reference_filter(single_reference).to_html }
- expect { reference_filter(multiple_references).to_html }.not_to exceed_query_limit(control_count)
+ expect { reference_filter(multiple_references).to_html }.not_to exceed_query_limit(control)
end
end
end
diff --git a/spec/lib/banzai/issuable_extractor_spec.rb b/spec/lib/banzai/issuable_extractor_spec.rb
index 5bbd98592e7..fe1a2bd9a2e 100644
--- a/spec/lib/banzai/issuable_extractor_spec.rb
+++ b/spec/lib/banzai/issuable_extractor_spec.rb
@@ -45,9 +45,9 @@ RSpec.describe Banzai::IssuableExtractor, feature_category: :team_planning do
second_call_queries = ActiveRecord::QueryRecorder.new do
extractor.extract([issue_link, work_item_link, merge_request_link])
- end.count
+ end
- expect(second_call_queries).to eq 0
+ expect(second_call_queries.count).to eq 0
end
end
end
diff --git a/spec/lib/banzai/reference_parser/snippet_parser_spec.rb b/spec/lib/banzai/reference_parser/snippet_parser_spec.rb
index 8f4148be2dc..0f3834c2dc8 100644
--- a/spec/lib/banzai/reference_parser/snippet_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/snippet_parser_spec.rb
@@ -37,11 +37,11 @@ RSpec.describe Banzai::ReferenceParser::SnippetParser, feature_category: :team_p
# Run this once to establish a baseline
visible_references(:public)
- control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
subject.nodes_visible_to_user(user, [link])
end
- expect { subject.nodes_visible_to_user(user, Array.new(10, link)) }.not_to exceed_all_query_limit(control_count.count)
+ expect { subject.nodes_visible_to_user(user, Array.new(10, link)) }.not_to exceed_all_query_limit(control)
end
it 'creates a reference for guest for a public snippet' do
diff --git a/spec/lib/gitlab/data_builder/pipeline_spec.rb b/spec/lib/gitlab/data_builder/pipeline_spec.rb
index ad7cd2dc736..5fa61b1680d 100644
--- a/spec/lib/gitlab/data_builder/pipeline_spec.rb
+++ b/spec/lib/gitlab/data_builder/pipeline_spec.rb
@@ -184,14 +184,14 @@ RSpec.describe Gitlab::DataBuilder::Pipeline, feature_category: :continuous_inte
create(:ci_build, :deploy_to_production, :with_deployment, user: user, project: project, pipeline: pipeline)
# We need `.to_json` as the build hook data is wrapped within `Gitlab::Lazy`
- control_count = ActiveRecord::QueryRecorder.new { described_class.build(pipeline.reload).to_json }.count
+ control = ActiveRecord::QueryRecorder.new { described_class.build(pipeline.reload).to_json }
# Adding more builds to the pipeline and serializing the data again
create_list(:ci_build, 3, user: user, project: project, pipeline: pipeline)
create(:ci_build, :start_review_app, :with_deployment, user: user, project: project, pipeline: pipeline)
create(:ci_build, :stop_review_app, :with_deployment, user: user, project: project, pipeline: pipeline)
- expect { described_class.build(pipeline.reload).to_json }.not_to exceed_query_limit(control_count)
+ expect { described_class.build(pipeline.reload).to_json }.not_to exceed_query_limit(control)
end
it "with multiple retried builds" do
@@ -201,14 +201,14 @@ RSpec.describe Gitlab::DataBuilder::Pipeline, feature_category: :continuous_inte
create(:ci_build, :deploy_to_production, :retried, :with_deployment, user: user, project: project, pipeline: pipeline)
# We need `.to_json` as the build hook data is wrapped within `Gitlab::Lazy`
- control_count = ActiveRecord::QueryRecorder.new { described_class.build(pipeline.reload).with_retried_builds.to_json }.count
+ control = ActiveRecord::QueryRecorder.new { described_class.build(pipeline.reload).with_retried_builds.to_json }
# Adding more builds to the pipeline and serializing the data again
create_list(:ci_build, 3, :retried, user: user, project: project, pipeline: pipeline)
create(:ci_build, :start_review_app, :retried, :with_deployment, user: user, project: project, pipeline: pipeline)
create(:ci_build, :stop_review_app, :retried, :with_deployment, user: user, project: project, pipeline: pipeline)
- expect { described_class.build(pipeline.reload).with_retried_builds.to_json }.not_to exceed_query_limit(control_count)
+ expect { described_class.build(pipeline.reload).with_retried_builds.to_json }.not_to exceed_query_limit(control)
end
end
end
diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb
index 71f9a7d0f0e..82daaba6448 100644
--- a/spec/lib/gitlab/git_access_spec.rb
+++ b/spec/lib/gitlab/git_access_spec.rb
@@ -1062,14 +1062,14 @@ RSpec.describe Gitlab::GitAccess, :aggregate_failures, feature_category: :system
# additional queries.
access.check('git-receive-pack', changes)
- control_count = ActiveRecord::QueryRecorder.new do
+ control = ActiveRecord::QueryRecorder.new do
access.check('git-receive-pack', changes)
end
changes = ['6f6d7e7ed 570e7b2ab refs/heads/master', '6f6d7e7ed 570e7b2ab refs/heads/feature']
# There is still an N+1 query with protected branches
- expect { access.check('git-receive-pack', changes) }.not_to exceed_query_limit(control_count).with_threshold(2)
+ expect { access.check('git-receive-pack', changes) }.not_to exceed_query_limit(control).with_threshold(2)
end
it 'raises TimeoutError when #check_access! raises a timeout error' do
diff --git a/spec/lib/gitlab/tracking/destinations/database_events_snowplow_spec.rb b/spec/lib/gitlab/tracking/destinations/database_events_snowplow_spec.rb
deleted file mode 100644
index 5a5c7123971..00000000000
--- a/spec/lib/gitlab/tracking/destinations/database_events_snowplow_spec.rb
+++ /dev/null
@@ -1,140 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::Tracking::Destinations::DatabaseEventsSnowplow, :do_not_stub_snowplow_by_default, feature_category: :application_instrumentation do
- let(:emitter) { SnowplowTracker::Emitter.new(endpoint: 'localhost', options: { buffer_size: 1 }) }
-
- let(:tracker) do
- SnowplowTracker::Tracker
- .new(
- emitters: [emitter],
- subject: SnowplowTracker::Subject.new,
- namespace: 'namespace',
- app_id: 'app_id'
- )
- end
-
- before do
- stub_application_setting(snowplow_app_id: '_abc123_')
- end
-
- around do |example|
- freeze_time { example.run }
- end
-
- context 'when snowplow is enabled' do
- before do
- allow(SnowplowTracker::AsyncEmitter)
- .to receive(:new)
- .with(endpoint: endpoint,
- options:
- {
- protocol: 'https',
- on_success: subject.method(:increment_successful_events_emissions),
- on_failure: subject.method(:failure_callback)
- }
- ).and_return(emitter)
-
- allow(SnowplowTracker::Tracker)
- .to receive(:new)
- .with(
- emitters: [emitter],
- subject: an_instance_of(SnowplowTracker::Subject),
- namespace: described_class::SNOWPLOW_NAMESPACE,
- app_id: '_abc123_'
- ).and_return(tracker)
- end
-
- describe '#event' do
- let(:endpoint) { 'localhost:9091' }
- let(:event_params) do
- {
- category: 'category',
- action: 'action',
- label: 'label',
- property: 'property',
- value: 1.5,
- context: nil,
- tstamp: (Time.now.to_f * 1000).to_i
- }
- end
-
- context 'when on gitlab.com environment' do
- let(:endpoint) { 'db-snowplow.trx.gitlab.net' }
-
- before do
- stub_application_setting(snowplow_database_collector_hostname: endpoint)
- end
-
- it 'sends event to tracker' do
- allow(Gitlab).to receive(:com?).and_return(true)
- allow(tracker).to receive(:track_struct_event).and_call_original
-
- subject.event('category', 'action', label: 'label', property: 'property', value: 1.5)
-
- expect(tracker).to have_received(:track_struct_event).with(event_params)
- end
- end
-
- it 'sends event to tracker' do
- allow(tracker).to receive(:track_struct_event).and_call_original
-
- subject.event('category', 'action', label: 'label', property: 'property', value: 1.5)
-
- expect(tracker).to have_received(:track_struct_event).with(event_params)
- end
-
- it 'increase total snowplow events counter' do
- counter = double
-
- expect(counter).to receive(:increment)
- expect(Gitlab::Metrics).to receive(:counter)
- .with(:gitlab_db_events_snowplow_events_total, 'Number of Snowplow events')
- .and_return(counter)
-
- subject.event('category', 'action', label: 'label', property: 'property', value: 1.5)
- end
- end
- end
-
- context 'for callbacks' do
- describe 'on success' do
- it 'increase gitlab_successful_snowplow_events_total counter' do
- counter = double
-
- expect(counter).to receive(:increment).with({}, 2)
- expect(Gitlab::Metrics).to receive(:counter)
- .with(
- :gitlab_db_events_snowplow_successful_events_total,
- 'Number of successful Snowplow events emissions').and_return(counter)
-
- subject.method(:increment_successful_events_emissions).call(2)
- end
- end
-
- describe 'on failure' do
- it 'increase gitlab_failed_snowplow_events_total counter and logs failures', :aggregate_failures do
- counter = double
- error_message = "Issue database_event_update failed to be reported to collector at localhost:9091"
- failures = [{ "e" => "se",
- "se_ca" => "Issue",
- "se_la" => "issues",
- "se_ac" => "database_event_update" }]
- allow(Gitlab::Metrics).to receive(:counter)
- .with(
- :gitlab_db_events_snowplow_successful_events_total,
- 'Number of successful Snowplow events emissions').and_call_original
-
- expect(Gitlab::AppLogger).to receive(:error).with(error_message)
- expect(counter).to receive(:increment).with({}, 1)
- expect(Gitlab::Metrics).to receive(:counter)
- .with(
- :gitlab_db_events_snowplow_failed_events_total,
- 'Number of failed Snowplow events emissions').and_return(counter)
-
- subject.method(:failure_callback).call(2, failures)
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/tracking_spec.rb b/spec/lib/gitlab/tracking_spec.rb
index 46213532071..6e4ab00d04f 100644
--- a/spec/lib/gitlab/tracking_spec.rb
+++ b/spec/lib/gitlab/tracking_spec.rb
@@ -165,38 +165,6 @@ RSpec.describe Gitlab::Tracking, feature_category: :application_instrumentation
end
end
- describe '.database_event' do
- context 'when the action is not passed in as a string' do
- it 'allows symbols' do
- expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)
-
- described_class.database_event('category', :some_action)
- end
-
- it 'allows nil' do
- expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)
-
- described_class.database_event('category', nil)
- end
-
- it 'allows integers' do
- expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)
-
- described_class.database_event('category', 1)
- end
- end
-
- it_behaves_like 'rescued error raised by destination class' do
- let(:category) { 'Issue' }
- let(:action) { 'created' }
- let(:destination_class) { Gitlab::Tracking::Destinations::DatabaseEventsSnowplow }
-
- subject(:tracking_method) { described_class.database_event(category, action) }
- end
-
- it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::DatabaseEventsSnowplow, :database_event
- end
-
describe '.event' do
context 'when the action is not passed in as a string' do
it 'allows symbols' do