diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-26 18:08:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-26 18:08:51 +0300 |
commit | a3a9c1103b0f023deafc9fc9307032085419ff7d (patch) | |
tree | d4c73cc6e63e4ba79b1a854a747142e02dd4250d /spec/lib | |
parent | 597d5ed08988cb00681eaf252d04ebae4bd24731 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/database/query_analyzers/query_recorder_spec.rb | 114 | ||||
-rw-r--r-- | spec/lib/gitlab/pagination/keyset/in_operator_optimization/strategies/record_loader_strategy_spec.rb | 8 |
2 files changed, 8 insertions, 114 deletions
diff --git a/spec/lib/gitlab/database/query_analyzers/query_recorder_spec.rb b/spec/lib/gitlab/database/query_analyzers/query_recorder_spec.rb deleted file mode 100644 index 22ff66ff55e..00000000000 --- a/spec/lib/gitlab/database/query_analyzers/query_recorder_spec.rb +++ /dev/null @@ -1,114 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Database::QueryAnalyzers::QueryRecorder, feature_category: :database, query_analyzers: false do - # We keep only the QueryRecorder analyzer running - around do |example| - described_class.with_suppressed(false) do - example.run - end - end - - context 'with query analyzer' do - let(:log_path) { Rails.root.join(described_class::LOG_PATH) } - let(:log_file) { described_class.log_file } - - after do - ::Gitlab::Database::QueryAnalyzer.instance.end!([described_class]) - end - - shared_examples_for 'an enabled query recorder' do - using RSpec::Parameterized::TableSyntax - - normalized_query = <<~SQL.strip.tr("\n", ' ') - SELECT \\\\"projects\\\\".\\\\"id\\\\" - FROM \\\\"projects\\\\" - WHERE \\\\"projects\\\\".\\\\"namespace_id\\\\" = \\? - AND \\\\"projects\\\\".\\\\"id\\\\" IN \\(\\?,\\?,\\?\\); - SQL - - where(:list_parameter, :bind_parameters) do - '$2, $3' | [1, 2, 3] - '$2, $3, $4' | [1, 2, 3, 4] - '$2 ,$3 ,$4 ,$5' | [1, 2, 3, 4, 5] - '$2 , $3 , $4 , $5, $6' | [1, 2, 3, 4, 5, 6] - '$2, $3 ,$4 , $5,$6,$7' | [1, 2, 3, 4, 5, 6, 7] - '$2,$3,$4,$5,$6,$7,$8' | [1, 2, 3, 4, 5, 6, 7, 8] - end - - with_them do - before do - allow(described_class).to receive(:analyze).and_call_original - allow(FileUtils).to receive(:mkdir_p) - .with(log_path) - end - - it 'logs normalized queries to a file' do - expect(File).to receive(:write) - .with(log_file, /^{"normalized":"#{normalized_query}/, mode: 'a') - - expect do - ApplicationRecord.connection.exec_query(<<~SQL.strip.tr("\n", ' '), 'SQL', bind_parameters) - SELECT "projects"."id" - FROM "projects" - WHERE "projects"."namespace_id" = $1 - AND "projects"."id" IN (#{list_parameter}); - SQL - end.not_to raise_error - end - end - end - - context 'on default branch' do - before do - stub_env('CI_MERGE_REQUEST_LABELS', nil) - stub_env('CI_DEFAULT_BRANCH', 'default_branch_name') - stub_env('CI_COMMIT_REF_NAME', 'default_branch_name') - - # This is needed to be able to stub_env the CI variable - ::Gitlab::Database::QueryAnalyzer.instance.begin!([described_class]) - end - - it_behaves_like 'an enabled query recorder' - end - - context 'on database merge requests' do - before do - stub_env('CI_MERGE_REQUEST_LABELS', 'database') - - # This is needed to be able to stub_env the CI variable - ::Gitlab::Database::QueryAnalyzer.instance.begin!([described_class]) - end - - it_behaves_like 'an enabled query recorder' - end - end - - describe '.log_file' do - let(:folder) { 'query_recorder' } - let(:extension) { 'ndjson' } - let(:default_name) { 'rspec' } - let(:job_name) { 'test-job-1' } - - subject { described_class.log_file.to_s } - - context 'when in CI' do - before do - stub_env('CI_JOB_NAME_SLUG', job_name) - end - - it { is_expected.to include("#{folder}/#{job_name}.#{extension}") } - it { is_expected.not_to include("#{folder}/#{default_name}.#{extension}") } - end - - context 'when not in CI' do - before do - stub_env('CI_JOB_NAME_SLUG', nil) - end - - it { is_expected.to include("#{folder}/#{default_name}.#{extension}") } - it { is_expected.not_to include("#{folder}/#{job_name}.#{extension}") } - end - end -end diff --git a/spec/lib/gitlab/pagination/keyset/in_operator_optimization/strategies/record_loader_strategy_spec.rb b/spec/lib/gitlab/pagination/keyset/in_operator_optimization/strategies/record_loader_strategy_spec.rb index 3fe858f33da..ddaf555dae6 100644 --- a/spec/lib/gitlab/pagination/keyset/in_operator_optimization/strategies/record_loader_strategy_spec.rb +++ b/spec/lib/gitlab/pagination/keyset/in_operator_optimization/strategies/record_loader_strategy_spec.rb @@ -32,6 +32,12 @@ RSpec.describe Gitlab::Pagination::Keyset::InOperatorOptimization::Strategies::R end end + let_it_be(:model_without_ignored_columns) do + Class.new(ApplicationRecord) do + self.table_name = 'projects' + end + end + subject(:strategy) { described_class.new(finder_query, model, order_by_columns) } describe '#initializer_columns' do @@ -70,6 +76,8 @@ RSpec.describe Gitlab::Pagination::Keyset::InOperatorOptimization::Strategies::R describe '#final_projections' do context 'when model does not have ignored columns' do + let(:model) { model_without_ignored_columns } + it 'does not specify the selected column names' do expect(strategy.final_projections).to contain_exactly("(#{described_class::RECORDS_COLUMN}).*") end |