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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-17 13:07:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-17 13:07:47 +0300
commitd670c3006e6e44901bce0d53cc4768d1d80ffa92 (patch)
tree8f65743c232e5b76850c4cc264ba15e1185815ff /spec/lib/gitlab/database
parenta5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (diff)
Add latest changes from gitlab-org/gitlab@14-0-stable-ee
Diffstat (limited to 'spec/lib/gitlab/database')
-rw-r--r--spec/lib/gitlab/database/migrations/observers/query_details_spec.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/migrations/observers/query_details_spec.rb b/spec/lib/gitlab/database/migrations/observers/query_details_spec.rb
new file mode 100644
index 00000000000..8aac3ed67c6
--- /dev/null
+++ b/spec/lib/gitlab/database/migrations/observers/query_details_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+require 'spec_helper'
+
+RSpec.describe Gitlab::Database::Migrations::Observers::QueryDetails do
+ subject { described_class.new }
+
+ let(:observation) { Gitlab::Database::Migrations::Observation.new(migration) }
+ let(:connection) { ActiveRecord::Base.connection }
+ let(:query) { "select date_trunc('day', $1::timestamptz) + $2 * (interval '1 hour')" }
+ let(:query_binds) { [Time.current, 3] }
+ let(:directory_path) { Dir.mktmpdir }
+ let(:log_file) { "#{directory_path}/#{migration}-query-details.json" }
+ let(:query_details) { Gitlab::Json.parse(File.read(log_file)) }
+ let(:migration) { 20210422152437 }
+
+ before do
+ stub_const('Gitlab::Database::Migrations::Instrumentation::RESULT_DIR', directory_path)
+ end
+
+ after do
+ FileUtils.remove_entry(directory_path)
+ end
+
+ it 'records details of executed queries' do
+ observe
+
+ expect(query_details.size).to eq(1)
+
+ log_entry = query_details[0]
+ start_time, end_time, sql, binds = log_entry.values_at('start_time', 'end_time', 'sql', 'binds')
+ start_time = DateTime.parse(start_time)
+ end_time = DateTime.parse(end_time)
+
+ aggregate_failures do
+ expect(sql).to include(query)
+ expect(start_time).to be_before(end_time)
+ expect(binds).to eq(query_binds.map { |b| connection.type_cast(b) })
+ end
+ end
+
+ it 'unsubscribes after the observation' do
+ observe
+
+ expect(subject).not_to receive(:record_sql_event)
+ run_query
+ end
+
+ def observe
+ subject.before
+ run_query
+ subject.after
+ subject.record(observation)
+ end
+
+ def run_query
+ connection.exec_query(query, 'SQL', query_binds)
+ end
+end