summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-25 18:08:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-25 18:08:50 +0000
commitad7ce32986c4b9e4af87c2895ef9a867cc5bb356 (patch)
treee8a8e9291434658484024ff00e236908123eb037 /spec
parent65f5f75e3a3b0b9f4ea6035294f81977fa8a2bb5 (diff)
downloadgitlab-ce-ad7ce32986c4b9e4af87c2895ef9a867cc5bb356.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/pipelines/components/dag/dag_annotations_spec.js112
-rw-r--r--spec/frontend/pipelines/components/dag/dag_graph_spec.js4
-rw-r--r--spec/frontend/pipelines/components/dag/dag_spec.js56
-rw-r--r--spec/frontend/pipelines/components/dag/mock_data.js40
-rw-r--r--spec/initializers/lograge_spec.rb30
-rw-r--r--spec/lib/backup/database_spec.rb67
-rw-r--r--spec/lib/gitlab/lograge/custom_options_spec.rb12
-rw-r--r--spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb29
-rw-r--r--spec/lib/gitlab/metrics/subscribers/active_record_spec.rb231
-rw-r--r--spec/lib/gitlab/metrics/transaction_spec.rb11
-rw-r--r--spec/support/helpers/test_env.rb12
11 files changed, 414 insertions, 190 deletions
diff --git a/spec/frontend/pipelines/components/dag/dag_annotations_spec.js b/spec/frontend/pipelines/components/dag/dag_annotations_spec.js
new file mode 100644
index 00000000000..5747c91bee8
--- /dev/null
+++ b/spec/frontend/pipelines/components/dag/dag_annotations_spec.js
@@ -0,0 +1,112 @@
+import { shallowMount, mount } from '@vue/test-utils';
+import { GlButton } from '@gitlab/ui';
+import DagAnnotations from '~/pipelines/components/dag/dag_annotations.vue';
+import { singleNote, multiNote } from './mock_data';
+
+describe('The DAG annotations', () => {
+ let wrapper;
+
+ const getColorBlock = () => wrapper.find('[data-testid="dag-color-block"]');
+ const getAllColorBlocks = () => wrapper.findAll('[data-testid="dag-color-block"]');
+ const getTextBlock = () => wrapper.find('[data-testid="dag-note-text"]');
+ const getAllTextBlocks = () => wrapper.findAll('[data-testid="dag-note-text"]');
+ const getToggleButton = () => wrapper.find(GlButton);
+
+ const createComponent = (propsData = {}, method = shallowMount) => {
+ if (wrapper?.destroy) {
+ wrapper.destroy();
+ }
+
+ wrapper = method(DagAnnotations, {
+ propsData,
+ data() {
+ return {
+ showList: true,
+ };
+ },
+ });
+ };
+
+ afterEach(() => {
+ wrapper.destroy();
+ wrapper = null;
+ });
+
+ describe('when there is one annotation', () => {
+ const currentNote = singleNote['dag-link103'];
+
+ beforeEach(() => {
+ createComponent({ annotations: singleNote });
+ });
+
+ it('displays the color block', () => {
+ expect(getColorBlock().exists()).toBe(true);
+ });
+
+ it('displays the text block', () => {
+ expect(getTextBlock().exists()).toBe(true);
+ expect(getTextBlock().text()).toBe(`${currentNote.source.name} → ${currentNote.target.name}`);
+ });
+
+ it('does not display the list toggle link', () => {
+ expect(getToggleButton().exists()).toBe(false);
+ });
+ });
+
+ describe('when there are multiple annoataions', () => {
+ beforeEach(() => {
+ createComponent({ annotations: multiNote });
+ });
+
+ it('displays a color block for each link', () => {
+ expect(getAllColorBlocks().length).toBe(Object.keys(multiNote).length);
+ });
+
+ it('displays a text block for each link', () => {
+ expect(getAllTextBlocks().length).toBe(Object.keys(multiNote).length);
+
+ Object.values(multiNote).forEach((item, idx) => {
+ expect(
+ getAllTextBlocks()
+ .at(idx)
+ .text(),
+ ).toBe(`${item.source.name} → ${item.target.name}`);
+ });
+ });
+
+ it('displays the list toggle link', () => {
+ expect(getToggleButton().exists()).toBe(true);
+ expect(getToggleButton().text()).toBe('Hide list');
+ });
+ });
+
+ describe('the list toggle', () => {
+ beforeEach(() => {
+ createComponent({ annotations: multiNote }, mount);
+ });
+
+ describe('clicking hide', () => {
+ it('hides listed items and changes text to show', () => {
+ expect(getAllTextBlocks().length).toBe(Object.keys(multiNote).length);
+ expect(getToggleButton().text()).toBe('Hide list');
+ getToggleButton().trigger('click');
+ return wrapper.vm.$nextTick().then(() => {
+ expect(getAllTextBlocks().length).toBe(0);
+ expect(getToggleButton().text()).toBe('Show list');
+ });
+ });
+ });
+
+ describe('clicking show', () => {
+ it('shows listed items and changes text to hide', () => {
+ getToggleButton().trigger('click');
+ getToggleButton().trigger('click');
+
+ return wrapper.vm.$nextTick().then(() => {
+ expect(getAllTextBlocks().length).toBe(Object.keys(multiNote).length);
+ expect(getToggleButton().text()).toBe('Hide list');
+ });
+ });
+ });
+ });
+});
diff --git a/spec/frontend/pipelines/components/dag/dag_graph_spec.js b/spec/frontend/pipelines/components/dag/dag_graph_spec.js
index 017461dfb84..e312791b01f 100644
--- a/spec/frontend/pipelines/components/dag/dag_graph_spec.js
+++ b/spec/frontend/pipelines/components/dag/dag_graph_spec.js
@@ -1,4 +1,4 @@
-import { mount } from '@vue/test-utils';
+import { shallowMount } from '@vue/test-utils';
import DagGraph from '~/pipelines/components/dag/dag_graph.vue';
import { IS_HIGHLIGHTED, LINK_SELECTOR, NODE_SELECTOR } from '~/pipelines/components/dag/constants';
import { highlightIn, highlightOut } from '~/pipelines/components/dag/interactions';
@@ -19,7 +19,7 @@ describe('The DAG graph', () => {
wrapper.destroy();
}
- wrapper = mount(DagGraph, {
+ wrapper = shallowMount(DagGraph, {
attachToDocument: true,
propsData,
data() {
diff --git a/spec/frontend/pipelines/components/dag/dag_spec.js b/spec/frontend/pipelines/components/dag/dag_spec.js
index 666b4cfaa2f..015076c5691 100644
--- a/spec/frontend/pipelines/components/dag/dag_spec.js
+++ b/spec/frontend/pipelines/components/dag/dag_spec.js
@@ -5,14 +5,18 @@ import waitForPromises from 'helpers/wait_for_promises';
import { GlAlert } from '@gitlab/ui';
import Dag from '~/pipelines/components/dag/dag.vue';
import DagGraph from '~/pipelines/components/dag/dag_graph.vue';
+import DagAnnotations from '~/pipelines/components/dag/dag_annotations.vue';
import {
+ ADD_NOTE,
+ REMOVE_NOTE,
+ REPLACE_NOTES,
DEFAULT,
PARSE_FAILURE,
LOAD_FAILURE,
UNSUPPORTED_DATA,
} from '~/pipelines/components/dag//constants';
-import { mockBaseData, tooSmallGraph, unparseableGraph } from './mock_data';
+import { mockBaseData, tooSmallGraph, unparseableGraph, singleNote, multiNote } from './mock_data';
describe('Pipeline DAG graph wrapper', () => {
let wrapper;
@@ -20,6 +24,7 @@ describe('Pipeline DAG graph wrapper', () => {
const getAlert = () => wrapper.find(GlAlert);
const getAllAlerts = () => wrapper.findAll(GlAlert);
const getGraph = () => wrapper.find(DagGraph);
+ const getNotes = () => wrapper.find(DagAnnotations);
const getErrorText = type => wrapper.vm.$options.errorTexts[type];
const dataPath = '/root/test/pipelines/90/dag.json';
@@ -134,4 +139,53 @@ describe('Pipeline DAG graph wrapper', () => {
});
});
});
+
+ describe('annotations', () => {
+ beforeEach(() => {
+ mock.onGet(dataPath).replyOnce(200, mockBaseData);
+ createComponent({ graphUrl: dataPath }, mount);
+ });
+
+ it('toggles on link mouseover and mouseout', () => {
+ const currentNote = singleNote['dag-link103'];
+
+ expect(getNotes().exists()).toBe(false);
+
+ return wrapper.vm
+ .$nextTick()
+ .then(waitForPromises)
+ .then(() => {
+ getGraph().vm.$emit('update-annotation', { type: ADD_NOTE, data: currentNote });
+ return wrapper.vm.$nextTick();
+ })
+ .then(() => {
+ expect(getNotes().exists()).toBe(true);
+ getGraph().vm.$emit('update-annotation', { type: REMOVE_NOTE, data: currentNote });
+ return wrapper.vm.$nextTick();
+ })
+ .then(() => {
+ expect(getNotes().exists()).toBe(false);
+ });
+ });
+
+ it('toggles on node and link click', () => {
+ expect(getNotes().exists()).toBe(false);
+
+ return wrapper.vm
+ .$nextTick()
+ .then(waitForPromises)
+ .then(() => {
+ getGraph().vm.$emit('update-annotation', { type: REPLACE_NOTES, data: multiNote });
+ return wrapper.vm.$nextTick();
+ })
+ .then(() => {
+ expect(getNotes().exists()).toBe(true);
+ getGraph().vm.$emit('update-annotation', { type: REPLACE_NOTES, data: {} });
+ return wrapper.vm.$nextTick();
+ })
+ .then(() => {
+ expect(getNotes().exists()).toBe(false);
+ });
+ });
+ });
});
diff --git a/spec/frontend/pipelines/components/dag/mock_data.js b/spec/frontend/pipelines/components/dag/mock_data.js
index 5de8697170a..e1733736755 100644
--- a/spec/frontend/pipelines/components/dag/mock_data.js
+++ b/spec/frontend/pipelines/components/dag/mock_data.js
@@ -388,3 +388,43 @@ export const parsedData = {
},
],
};
+
+export const singleNote = {
+ 'dag-link103': {
+ uid: 'dag-link103',
+ source: {
+ name: 'canary_a',
+ color: '#b31756',
+ },
+ target: {
+ name: 'production_a',
+ color: '#b24800',
+ },
+ },
+};
+
+export const multiNote = {
+ ...singleNote,
+ 'dag-link104': {
+ uid: 'dag-link104',
+ source: {
+ name: 'build_a',
+ color: '#e17223',
+ },
+ target: {
+ name: 'test_c',
+ color: '#006887',
+ },
+ },
+ 'dag-link105': {
+ uid: 'dag-link105',
+ source: {
+ name: 'test_c',
+ color: '#006887',
+ },
+ target: {
+ name: 'post_test_c',
+ color: '#3547de',
+ },
+ },
+};
diff --git a/spec/initializers/lograge_spec.rb b/spec/initializers/lograge_spec.rb
index 4d10d218606..de722764bf4 100644
--- a/spec/initializers/lograge_spec.rb
+++ b/spec/initializers/lograge_spec.rb
@@ -152,5 +152,35 @@ RSpec.describe 'lograge', type: :request do
expect(log_data['etag_route']).to eq(etag_route)
end
end
+
+ context 'with transaction' do
+ let(:transaction) { Gitlab::Metrics::WebTransaction.new({}) }
+
+ before do
+ allow(Gitlab::Metrics::Transaction).to receive(:current).and_return(transaction)
+ end
+
+ context 'when RequestStore is enabled', :request_store do
+ context 'with db payload' do
+ it 'includes db counters', :request_store do
+ ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
+ subscriber.process_action(event)
+
+ expect(log_data).to include("db_count" => 1, "db_write_count" => 0, "db_cached_count" => 0)
+ end
+ end
+ end
+
+ context 'when RequestStore is disabled' do
+ context 'with db payload' do
+ it 'does not include db counters' do
+ ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
+ subscriber.process_action(event)
+
+ expect(log_data).not_to include("db_count" => 1, "db_write_count" => 0, "db_cached_count" => 0)
+ end
+ end
+ end
+ end
end
end
diff --git a/spec/lib/backup/database_spec.rb b/spec/lib/backup/database_spec.rb
deleted file mode 100644
index 81a5219680f..00000000000
--- a/spec/lib/backup/database_spec.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-describe Backup::Database do
- let(:progress) { double('progress', print: nil, puts: nil) }
-
- describe '#dump' do
- subject { described_class.new(progress).dump }
-
- let(:pg_schema) { nil }
- let(:backup_config) { double('config', pg_schema: pg_schema, path: File.join(Rails.root, 'tmp')) }
-
- before do
- allow(Settings).to receive(:backup).and_return(backup_config)
- allow(Process).to receive(:waitpid)
- end
-
- it 'does not limit pg_dump to any specific schema' do
- expect(Process).to receive(:spawn) do |*cmd, _|
- expect(cmd.join(' ')).not_to include('-n')
- end
-
- subject
- end
-
- it 'includes option to drop objects before restoration' do
- expect(Process).to receive(:spawn) do |*cmd, _|
- expect(cmd.join(' ')).to include('--clean')
- end
-
- subject
- end
-
- context 'with pg_schema configured explicitly' do
- let(:pg_schema) { 'some_schema' }
-
- it 'calls pg_dump' do
- expect(Process).to receive(:spawn) do |*cmd, _|
- expect(cmd.join(' ')).to start_with('pg_dump')
- end
-
- subject
- end
-
- it 'limits the psql dump to the specified schema' do
- expect(Process).to receive(:spawn) do |*cmd, _|
- expect(cmd.join(' ')).to include("-n #{pg_schema}")
- end
-
- subject
- end
-
- context 'extra schemas' do
- Gitlab::Database::EXTRA_SCHEMAS.each do |schema|
- it "includes the extra schema #{schema}" do
- expect(Process).to receive(:spawn) do |*cmd, _|
- expect(cmd.join(' ')).to include("-n #{schema}")
- end
-
- subject
- end
- end
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/lograge/custom_options_spec.rb b/spec/lib/gitlab/lograge/custom_options_spec.rb
index 2535664aa34..550f8c17f04 100644
--- a/spec/lib/gitlab/lograge/custom_options_spec.rb
+++ b/spec/lib/gitlab/lograge/custom_options_spec.rb
@@ -44,18 +44,6 @@ RSpec.describe Gitlab::Lograge::CustomOptions do
end
end
- context 'with transaction' do
- let(:transaction) { Gitlab::Metrics::WebTransaction.new({}) }
-
- before do
- allow(Gitlab::Metrics::Transaction).to receive(:current).and_return(transaction)
- end
-
- it 'adds db counters' do
- expect(subject).to include(:db_count, :db_write_count, :db_cached_count)
- end
- end
-
it 'adds the user id' do
expect(subject[:user_id]).to eq('test')
end
diff --git a/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb b/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
index c800f5c1e06..c66d8b1075c 100644
--- a/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
+++ b/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
@@ -18,8 +18,20 @@ RSpec.describe Gitlab::Metrics::SidekiqMiddleware do
middleware.call(worker, message, :test) do
ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
end
+ end
+
+ it 'prevents database counters from leaking to the next transaction' do
+ worker = double(:worker, class: double(:class, name: 'TestWorker'))
- expect(message).to include(:db_count, :db_write_count, :db_cached_count)
+ 2.times do
+ Gitlab::WithRequestStore.with_request_store do
+ middleware.call(worker, message, :test) do
+ ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
+ end
+ end
+ end
+
+ expect(message).to include(db_count: 1, db_write_count: 0, db_cached_count: 0)
end
it 'tracks the transaction (for messages without `enqueued_at`)', :aggregate_failures do
@@ -35,19 +47,20 @@ RSpec.describe Gitlab::Metrics::SidekiqMiddleware do
middleware.call(worker, {}, :test) { nil }
end
- it 'tracks any raised exceptions', :aggregate_failures do
+ it 'tracks any raised exceptions', :aggregate_failures, :request_store do
worker = double(:worker, class: double(:class, name: 'TestWorker'))
expect_any_instance_of(Gitlab::Metrics::Transaction)
- .to receive(:run).and_raise(RuntimeError)
-
- expect_any_instance_of(Gitlab::Metrics::Transaction)
.to receive(:add_event).with(:sidekiq_exception)
- expect { middleware.call(worker, message, :test) }
- .to raise_error(RuntimeError)
+ expect do
+ middleware.call(worker, message, :test) do
+ ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
+ raise RuntimeError
+ end
+ end.to raise_error(RuntimeError)
- expect(message).to include(:db_count, :db_write_count, :db_cached_count)
+ expect(message).to include(db_count: 1, db_write_count: 0, db_cached_count: 0)
end
end
end
diff --git a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
index 701f170b8ed..2fd5dd1d83b 100644
--- a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
+++ b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
@@ -28,60 +28,45 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do
end
describe 'with a current transaction' do
- shared_examples 'read only query' do
- it 'increments only db count value' do
+ shared_examples 'track executed query' do
+ before do
allow(subscriber).to receive(:current_transaction)
- .at_least(:once)
- .and_return(transaction)
-
- expect(transaction).to receive(:increment)
- .with(:db_count, 1)
-
- expect(transaction).not_to receive(:increment)
- .with(:db_cached_count, 1)
-
- expect(transaction).not_to receive(:increment)
- .with(:db_write_count, 1)
-
- subscriber.sql(event)
+ .at_least(:once)
+ .and_return(transaction)
end
- end
-
- shared_examples 'write query' do
- it 'increments db_write_count and db_count value' do
- expect(subscriber).to receive(:current_transaction)
- .at_least(:once)
- .and_return(transaction)
- expect(transaction).to receive(:increment)
- .with(:db_count, 1)
-
- expect(transaction).not_to receive(:increment)
- .with(:db_cached_count, 1)
-
- expect(transaction).to receive(:increment)
- .with(:db_write_count, 1)
+ it 'increments only db count value' do
+ described_class::DB_COUNTERS.each do |counter|
+ if expected_counters[counter] > 0
+ expect(transaction).to receive(:increment).with(counter, 1)
+ else
+ expect(transaction).not_to receive(:increment).with(counter, 1)
+ end
+ end
subscriber.sql(event)
end
- end
- shared_examples 'cached query' do
- it 'increments db_cached_count and db_count value' do
- expect(subscriber).to receive(:current_transaction)
- .at_least(:once)
- .and_return(transaction)
-
- expect(transaction).to receive(:increment)
- .with(:db_count, 1)
-
- expect(transaction).to receive(:increment)
- .with(:db_cached_count, 1)
-
- expect(transaction).not_to receive(:increment)
- .with(:db_write_count, 1)
-
- subscriber.sql(event)
+ context 'when RequestStore is enabled' do
+ it 'caches db count value', :request_store, :aggregate_failures do
+ subscriber.sql(event)
+
+ described_class::DB_COUNTERS.each do |counter|
+ expect(Gitlab::SafeRequestStore[counter].to_i).to eq expected_counters[counter]
+ end
+ end
+
+ it 'prevents db counters from leaking to the next transaction' do
+ 2.times do
+ Gitlab::WithRequestStore.with_request_store do
+ subscriber.sql(event)
+
+ described_class::DB_COUNTERS.each do |counter|
+ expect(Gitlab::SafeRequestStore[counter].to_i).to eq expected_counters[counter]
+ end
+ end
+ end
+ end
end
end
@@ -93,66 +78,96 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do
subscriber.sql(event)
end
- it_behaves_like 'read only query'
+ context 'with read query' do
+ let(:expected_counters) do
+ {
+ db_count: 1,
+ db_write_count: 0,
+ db_cached_count: 0
+ }
+ end
+
+ it_behaves_like 'track executed query'
- context 'with select for update sql event' do
- let(:payload) { { sql: 'SELECT * FROM users WHERE id = 10 FOR UPDATE' } }
+ context 'with only select' do
+ let(:payload) { { sql: 'WITH active_milestones AS (SELECT COUNT(*), state FROM milestones GROUP BY state) SELECT * FROM active_milestones' } }
- it_behaves_like 'write query'
+ it_behaves_like 'track executed query'
+ end
end
- context 'with common table expression' do
- context 'with insert' do
- let(:payload) { { sql: 'WITH archived_rows AS (SELECT * FROM users WHERE archived = true) INSERT INTO products_log SELECT * FROM archived_rows' } }
+ context 'write query' do
+ let(:expected_counters) do
+ {
+ db_count: 1,
+ db_write_count: 1,
+ db_cached_count: 0
+ }
+ end
+
+ context 'with select for update sql event' do
+ let(:payload) { { sql: 'SELECT * FROM users WHERE id = 10 FOR UPDATE' } }
- it_behaves_like 'write query'
+ it_behaves_like 'track executed query'
end
- context 'with only select' do
- let(:payload) { { sql: 'WITH active_milestones AS (SELECT COUNT(*), state FROM milestones GROUP BY state) SELECT * FROM active_milestones' } }
+ context 'with common table expression' do
+ context 'with insert' do
+ let(:payload) { { sql: 'WITH archived_rows AS (SELECT * FROM users WHERE archived = true) INSERT INTO products_log SELECT * FROM archived_rows' } }
- it_behaves_like 'read only query'
+ it_behaves_like 'track executed query'
+ end
end
- end
- context 'with delete sql event' do
- let(:payload) { { sql: 'DELETE FROM users where id = 10' } }
+ context 'with delete sql event' do
+ let(:payload) { { sql: 'DELETE FROM users where id = 10' } }
- it_behaves_like 'write query'
- end
+ it_behaves_like 'track executed query'
+ end
- context 'with insert sql event' do
- let(:payload) { { sql: 'INSERT INTO project_ci_cd_settings (project_id) SELECT id FROM projects' } }
+ context 'with insert sql event' do
+ let(:payload) { { sql: 'INSERT INTO project_ci_cd_settings (project_id) SELECT id FROM projects' } }
- it_behaves_like 'write query'
- end
+ it_behaves_like 'track executed query'
+ end
- context 'with update sql event' do
- let(:payload) { { sql: 'UPDATE users SET admin = true WHERE id = 10' } }
+ context 'with update sql event' do
+ let(:payload) { { sql: 'UPDATE users SET admin = true WHERE id = 10' } }
- it_behaves_like 'write query'
+ it_behaves_like 'track executed query'
+ end
end
- context 'with cached payload ' do
- let(:payload) do
+ context 'with cached query' do
+ let(:expected_counters) do
{
- sql: 'SELECT * FROM users WHERE id = 10',
- cached: true
+ db_count: 1,
+ db_write_count: 0,
+ db_cached_count: 1
}
end
- it_behaves_like 'cached query'
- end
+ context 'with cached payload ' do
+ let(:payload) do
+ {
+ sql: 'SELECT * FROM users WHERE id = 10',
+ cached: true
+ }
+ end
- context 'with cached payload name' do
- let(:payload) do
- {
- sql: 'SELECT * FROM users WHERE id = 10',
- name: 'CACHE'
- }
+ it_behaves_like 'track executed query'
end
- it_behaves_like 'cached query'
+ context 'with cached payload name' do
+ let(:payload) do
+ {
+ sql: 'SELECT * FROM users WHERE id = 10',
+ name: 'CACHE'
+ }
+ end
+
+ it_behaves_like 'track executed query'
+ end
end
context 'events are internal to Rails or irrelevant' do
@@ -215,4 +230,54 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do
end
end
end
+
+ describe 'self.db_counter_payload' do
+ before do
+ allow(subscriber).to receive(:current_transaction)
+ .at_least(:once)
+ .and_return(transaction)
+ end
+
+ context 'when RequestStore is enabled', :request_store do
+ context 'when query is executed' do
+ let(:expected_payload) do
+ {
+ db_count: 1,
+ db_cached_count: 0,
+ db_write_count: 0
+ }
+ end
+
+ it 'returns correct payload' do
+ subscriber.sql(event)
+
+ expect(described_class.db_counter_payload).to eq(expected_payload)
+ end
+ end
+
+ context 'when query is not executed' do
+ let(:expected_payload) do
+ {
+ db_count: 0,
+ db_cached_count: 0,
+ db_write_count: 0
+ }
+ end
+
+ it 'returns correct payload' do
+ expect(described_class.db_counter_payload).to eq(expected_payload)
+ end
+ end
+ end
+
+ context 'when RequestStore is disabled' do
+ let(:expected_payload) { {} }
+
+ it 'returns empty payload' do
+ subscriber.sql(event)
+
+ expect(described_class.db_counter_payload).to eq(expected_payload)
+ end
+ end
+ end
end
diff --git a/spec/lib/gitlab/metrics/transaction_spec.rb b/spec/lib/gitlab/metrics/transaction_spec.rb
index a838980deae..e64179bd5c1 100644
--- a/spec/lib/gitlab/metrics/transaction_spec.rb
+++ b/spec/lib/gitlab/metrics/transaction_spec.rb
@@ -114,15 +114,4 @@ RSpec.describe Gitlab::Metrics::Transaction do
transaction.set(:meow, 1)
end
end
-
- describe '#get' do
- let(:prometheus_metric) { instance_double(Prometheus::Client::Counter, get: nil) }
-
- it 'gets a metric' do
- expect(described_class).to receive(:fetch_metric).with(:counter, :gitlab_transaction_meow_total).and_return(prometheus_metric)
- expect(prometheus_metric).to receive(:get)
-
- transaction.get(:meow, :counter)
- end
- end
end
diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb
index db70c3e8248..09d16f306fd 100644
--- a/spec/support/helpers/test_env.rb
+++ b/spec/support/helpers/test_env.rb
@@ -169,8 +169,9 @@ module TestEnv
task: "gitlab:gitaly:install[#{install_gitaly_args}]") do
Gitlab::SetupHelper::Gitaly.create_configuration(gitaly_dir, { 'default' => repos_path }, force: true)
Gitlab::SetupHelper::Praefect.create_configuration(gitaly_dir, { 'praefect' => repos_path }, force: true)
- start_gitaly(gitaly_dir)
end
+
+ start_gitaly(gitaly_dir)
end
def gitaly_socket_path
@@ -463,7 +464,6 @@ module TestEnv
end
def component_timed_setup(component, install_dir:, version:, task:)
- puts "\n==> Setting up #{component}..."
start = Time.now
ensure_component_dir_name_is_correct!(component, install_dir)
@@ -472,22 +472,22 @@ module TestEnv
return if File.exist?(install_dir) && ci?
if component_needs_update?(install_dir, version)
+ puts "\n==> Setting up #{component}..."
# Cleanup the component entirely to ensure we start fresh
FileUtils.rm_rf(install_dir)
unless system('rake', task)
raise ComponentFailedToInstallError
end
- end
- yield if block_given?
+ yield if block_given?
+ puts " #{component} set up in #{Time.now - start} seconds...\n"
+ end
rescue ComponentFailedToInstallError
puts "\n#{component} failed to install, cleaning up #{install_dir}!\n"
FileUtils.rm_rf(install_dir)
exit 1
- ensure
- puts " #{component} set up in #{Time.now - start} seconds...\n"
end
def ci?