diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/support/shared_examples/lib/gitlab | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab')
5 files changed, 216 insertions, 4 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb index 0df1af3b10a..9c95d1ff9d9 100644 --- a/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb @@ -843,6 +843,17 @@ RSpec.shared_examples 'trace with enabled live trace feature' do expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError) expect(build.job_artifacts_trace.file.exists?).to be_truthy end + + context 'when live trace chunks still exist' do + before do + create(:ci_build_trace_chunk, build: build) + end + + it 'removes the traces' do + expect { subject }.to raise_error(Gitlab::Ci::Trace::AlreadyArchivedError) + expect(build.trace_chunks).to be_empty + end + end end context 'when job is not finished yet' do diff --git a/spec/support/shared_examples/lib/gitlab/database/cte_materialized_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/database/cte_materialized_shared_examples.rb new file mode 100644 index 00000000000..88e6ffd15a8 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/database/cte_materialized_shared_examples.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'CTE with MATERIALIZED keyword examples' do + describe 'adding MATERIALIZE to the CTE' do + let(:options) { {} } + + before do + # Clear the cached value before the test + Gitlab::Database::AsWithMaterialized.clear_memoization(:materialized_supported) + end + + context 'when PG version is <12' do + it 'does not add MATERIALIZE keyword' do + allow(Gitlab::Database).to receive(:version).and_return('11.1') + + expect(query).to include(expected_query_block_without_materialized) + end + end + + context 'when PG version is >=12' do + it 'adds MATERIALIZE keyword' do + allow(Gitlab::Database).to receive(:version).and_return('12.1') + + expect(query).to include(expected_query_block_with_materialized) + end + + context 'when version is higher than 12' do + it 'adds MATERIALIZE keyword' do + allow(Gitlab::Database).to receive(:version).and_return('15.1') + + expect(query).to include(expected_query_block_with_materialized) + end + end + + context 'when materialized is disabled' do + let(:options) { { materialized: false } } + + it 'does not add MATERIALIZE keyword' do + expect(query).to include(expected_query_block_without_materialized) + end + end + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/sidekiq_middleware/metrics_middleware_with_worker_attribution_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/sidekiq_middleware/metrics_middleware_with_worker_attribution_shared_examples.rb new file mode 100644 index 00000000000..48dc47e8e9b --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/sidekiq_middleware/metrics_middleware_with_worker_attribution_shared_examples.rb @@ -0,0 +1,132 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'metrics middleware with worker attribution' do + subject { described_class.new } + + let(:queue) { :test } + let(:worker_class) { worker.class } + let(:job) { {} } + let(:default_labels) do + { queue: queue.to_s, + worker: worker_class.to_s, + boundary: "", + external_dependencies: "no", + feature_category: "", + urgency: "low" } + end + + context "when workers are not attributed" do + before do + stub_const('TestNonAttributedWorker', Class.new) + TestNonAttributedWorker.class_eval do + include Sidekiq::Worker + end + end + + it_behaves_like "a metrics middleware" do + let(:worker) { TestNonAttributedWorker.new } + let(:labels) { default_labels.merge(urgency: "") } + end + end + + context "when a worker is wrapped into ActiveJob" do + before do + stub_const('TestWrappedWorker', Class.new) + TestWrappedWorker.class_eval do + include Sidekiq::Worker + end + end + + it_behaves_like "a metrics middleware" do + let(:job) do + { + "class" => ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper, + "wrapped" => TestWrappedWorker + } + end + + let(:worker) { TestWrappedWorker.new } + let(:labels) { default_labels.merge(urgency: "") } + end + end + + context "when workers are attributed" do + def create_attributed_worker_class(urgency, external_dependencies, resource_boundary, category) + klass = Class.new do + include Sidekiq::Worker + include WorkerAttributes + + urgency urgency if urgency + worker_has_external_dependencies! if external_dependencies + worker_resource_boundary resource_boundary unless resource_boundary == :unknown + feature_category category unless category.nil? + end + stub_const("TestAttributedWorker", klass) + end + + let(:urgency) { nil } + let(:external_dependencies) { false } + let(:resource_boundary) { :unknown } + let(:feature_category) { nil } + let(:worker_class) { create_attributed_worker_class(urgency, external_dependencies, resource_boundary, feature_category) } + let(:worker) { worker_class.new } + + context "high urgency" do + it_behaves_like "a metrics middleware" do + let(:urgency) { :high } + let(:labels) { default_labels.merge(urgency: "high") } + end + end + + context "no urgency" do + it_behaves_like "a metrics middleware" do + let(:urgency) { :throttled } + let(:labels) { default_labels.merge(urgency: "throttled") } + end + end + + context "external dependencies" do + it_behaves_like "a metrics middleware" do + let(:external_dependencies) { true } + let(:labels) { default_labels.merge(external_dependencies: "yes") } + end + end + + context "cpu boundary" do + it_behaves_like "a metrics middleware" do + let(:resource_boundary) { :cpu } + let(:labels) { default_labels.merge(boundary: "cpu") } + end + end + + context "memory boundary" do + it_behaves_like "a metrics middleware" do + let(:resource_boundary) { :memory } + let(:labels) { default_labels.merge(boundary: "memory") } + end + end + + context "feature category" do + it_behaves_like "a metrics middleware" do + let(:feature_category) { :authentication } + let(:labels) { default_labels.merge(feature_category: "authentication") } + end + end + + context "combined" do + it_behaves_like "a metrics middleware" do + let(:urgency) { :high } + let(:external_dependencies) { true } + let(:resource_boundary) { :cpu } + let(:feature_category) { :authentication } + let(:labels) do + default_labels.merge( + urgency: "high", + external_dependencies: "yes", + boundary: "cpu", + feature_category: "authentication") + end + end + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/sql/set_operator_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/sql/set_operator_shared_examples.rb index 73beef06855..aa6a51c3646 100644 --- a/spec/support/shared_examples/lib/gitlab/sql/set_operator_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/sql/set_operator_shared_examples.rb @@ -43,4 +43,33 @@ RSpec.shared_examples 'SQL set operator' do |operator_keyword| expect(set_operator.to_sql).to eq('NULL') end end + + describe 'remove_order parameter' do + let(:scopes) do + [ + User.where(id: 1).order(id: :desc).limit(1), + User.where(id: 2).order(id: :asc).limit(1) + ] + end + + subject(:union_query) { described_class.new(scopes, remove_order: remove_order).to_sql } + + context 'when remove_order: true' do + let(:remove_order) { true } + + it 'removes the ORDER BY from the query' do + expect(union_query).not_to include('ORDER BY "users"."id" DESC') + expect(union_query).not_to include('ORDER BY "users"."id" ASC') + end + end + + context 'when remove_order: false' do + let(:remove_order) { false } + + it 'does not remove the ORDER BY from the query' do + expect(union_query).to include('ORDER BY "users"."id" DESC') + expect(union_query).to include('ORDER BY "users"."id" ASC') + end + end + end end diff --git a/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb index aa6e64a3820..4b956c2b566 100644 --- a/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb @@ -14,10 +14,6 @@ RSpec.shared_examples 'a daily tracked issuable event' do expect(track_action(author: user1)).to be_truthy expect(track_action(author: user1)).to be_truthy expect(track_action(author: user2)).to be_truthy - expect(track_action(author: user3, time: time - 3.days)).to be_truthy - - expect(count_unique(date_from: time, date_to: time)).to eq(2) - expect(count_unique(date_from: time - 5.days, date_to: 1.day.since(time))).to eq(3) end end |