diff options
Diffstat (limited to 'spec/lib/gitlab/ci/pipeline/logger_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/logger_spec.rb | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/spec/lib/gitlab/ci/pipeline/logger_spec.rb b/spec/lib/gitlab/ci/pipeline/logger_spec.rb index a488bc184f8..f31361431f2 100644 --- a/spec/lib/gitlab/ci/pipeline/logger_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/logger_spec.rb @@ -47,13 +47,15 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Logger do end def loggable_data(count:, db_count: nil) - keys = %w[ + database_name = Ci::ApplicationRecord.connection.pool.db_config.name + + keys = %W[ expensive_operation_duration_s expensive_operation_db_count expensive_operation_db_primary_count expensive_operation_db_primary_duration_s - expensive_operation_db_main_count - expensive_operation_db_main_duration_s + expensive_operation_db_#{database_name}_count + expensive_operation_db_#{database_name}_duration_s ] data = keys.each.with_object({}) do |key, accumulator| @@ -75,7 +77,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Logger do end context 'with a single query' do - let(:operation) { -> { Project.count } } + let(:operation) { -> { Ci::Pipeline.count } } it { is_expected.to eq(operation.call) } @@ -201,6 +203,35 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Logger do expect(commit).to be_truthy end end + + context 'when project is not passed and pipeline is not persisted' do + let(:project) {} + let(:pipeline) { build(:ci_pipeline) } + + let(:loggable_data) do + { + 'class' => described_class.name.to_s, + 'pipeline_persisted' => false, + 'pipeline_creation_service_duration_s' => a_kind_of(Numeric), + 'pipeline_creation_caller' => 'source', + 'pipeline_save_duration_s' => { + 'avg' => 60, 'count' => 1, 'max' => 60, 'min' => 60 + }, + 'pipeline_creation_duration_s' => { + 'avg' => 20, 'count' => 2, 'max' => 30, 'min' => 10 + } + } + end + + it 'logs to application.json' do + expect(Gitlab::AppJsonLogger) + .to receive(:info) + .with(a_hash_including(loggable_data)) + .and_call_original + + expect(commit).to be_truthy + end + end end context 'when the feature flag is disabled' do |