diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/support/shared_examples/lib | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/support/shared_examples/lib')
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb | 74 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb | 20 |
2 files changed, 94 insertions, 0 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 9c95d1ff9d9..3760325675a 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 @@ -29,6 +29,34 @@ RSpec.shared_examples 'common trace features' do end end + describe '#read' do + context 'gitlab_ci_archived_trace_consistent_reads feature flag enabled' do + before do + stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: trace.job.project) + end + + it 'calls ::Gitlab::Database::LoadBalancing::Sticking.unstick_or_continue_sticking' do + expect(::Gitlab::Database::LoadBalancing::Sticking).to receive(:unstick_or_continue_sticking) + .with(described_class::LOAD_BALANCING_STICKING_NAMESPACE, trace.job.id) + .and_call_original + + trace.read { |stream| stream } + end + end + + context 'gitlab_ci_archived_trace_consistent_reads feature flag disabled' do + before do + stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: false) + end + + it 'does not call ::Gitlab::Database::LoadBalancing::Sticking.unstick_or_continue_sticking' do + expect(::Gitlab::Database::LoadBalancing::Sticking).not_to receive(:unstick_or_continue_sticking) + + trace.read { |stream| stream } + end + end + end + describe '#extract_coverage' do let(:regex) { '\(\d+.\d+\%\) covered' } @@ -253,6 +281,52 @@ RSpec.shared_examples 'common trace features' do describe '#archive!' do subject { trace.archive! } + context 'when live trace chunks exists' do + before do + # Build a trace_chunk manually + # It is possible to do so with trace.set but only if ci_enable_live_trace FF is enabled + # + # We need the job to have a trace_chunk because we only use #stick in + # the case where trace_chunks exist. + stream = Gitlab::Ci::Trace::Stream.new do + Gitlab::Ci::Trace::ChunkedIO.new(trace.job) + end + + stream.set(+"12\n34") + end + + # We check the before setup actually sets up job trace_chunks + it 'has job trace_chunks' do + expect(trace.job.trace_chunks).to be_present + end + + context 'gitlab_ci_archived_trace_consistent_reads feature flag enabled' do + before do + stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: trace.job.project) + end + + it 'calls ::Gitlab::Database::LoadBalancing::Sticking.stick' do + expect(::Gitlab::Database::LoadBalancing::Sticking).to receive(:stick) + .with(described_class::LOAD_BALANCING_STICKING_NAMESPACE, trace.job.id) + .and_call_original + + subject + end + end + + context 'gitlab_ci_archived_trace_consistent_reads feature flag disabled' do + before do + stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: false) + end + + it 'does not call ::Gitlab::Database::LoadBalancing::Sticking.stick' do + expect(::Gitlab::Database::LoadBalancing::Sticking).not_to receive(:stick) + + subject + end + end + end + context 'when build status is success' do let!(:build) { create(:ci_build, :success, :trace_live) } diff --git a/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb new file mode 100644 index 00000000000..5baa6478225 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'tracks assignment and records the subject' do |experiment, subject_type| + it 'tracks the assignment', :experiment do + expect(experiment(experiment)) + .to track(:assignment) + .with_context(subject_type => subject) + .on_next_instance + + action + end + + it 'records the subject' do + stub_experiments(experiment => :candidate) + + expect(Experiment).to receive(:add_subject).with(experiment.to_s, variant: :experimental, subject: subject) + + action + end +end |