diff options
Diffstat (limited to 'spec/services/ci/test_failure_history_service_spec.rb')
-rw-r--r-- | spec/services/ci/test_failure_history_service_spec.rb | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/spec/services/ci/test_failure_history_service_spec.rb b/spec/services/ci/test_failure_history_service_spec.rb index c19df6e217b..10f6c6f5007 100644 --- a/spec/services/ci/test_failure_history_service_spec.rb +++ b/spec/services/ci/test_failure_history_service_spec.rb @@ -3,16 +3,19 @@ require 'spec_helper' RSpec.describe Ci::TestFailureHistoryService, :aggregate_failures do - describe '#execute' do - let(:project) { create(:project) } - let(:pipeline) { create(:ci_empty_pipeline, status: :created, project: project) } + let_it_be(:project) { create(:project, :repository) } + + let_it_be_with_reload(:pipeline) do + create(:ci_pipeline, status: :created, project: project, ref: project.default_branch) + end + describe '#execute' do subject(:execute_service) { described_class.new(pipeline).execute } context 'when pipeline has failed builds with test reports' do - before do + let_it_be(:job) do # The test report has 2 unit test failures - create(:ci_build, :failed, :test_reports, pipeline: pipeline, project: project) + create(:ci_build, :failed, :test_reports, pipeline: pipeline) end it 'creates unit test failures records' do @@ -22,6 +25,14 @@ RSpec.describe Ci::TestFailureHistoryService, :aggregate_failures do expect(Ci::UnitTestFailure.count).to eq(2) end + it 'assigns partition_id to Ci::UnitTestFailure' do + execute_service + + unit_test_failure_partition_ids = Ci::UnitTestFailure.distinct.pluck(:partition_id) + + expect(unit_test_failure_partition_ids).to match_array([job.partition_id]) + end + context 'when pipeline is not for the default branch' do before do pipeline.update_column(:ref, 'new-feature') @@ -67,7 +78,7 @@ RSpec.describe Ci::TestFailureHistoryService, :aggregate_failures do # This other test report has 1 unique unit test failure which brings us to 3 total failures across all builds # thus exceeding the limit of 2 for MAX_TRACKABLE_FAILURES - create(:ci_build, :failed, :test_reports_with_duplicate_failed_test_names, pipeline: pipeline, project: project) + create(:ci_build, :failed, :test_reports_with_duplicate_failed_test_names, pipeline: pipeline) end it 'does not persist data' do @@ -82,7 +93,7 @@ RSpec.describe Ci::TestFailureHistoryService, :aggregate_failures do context 'when test failure data have duplicates within the same payload (happens when the JUnit report has duplicate unit test names but have different failures)' do before do # The test report has 2 unit test failures but with the same unit test keys - create(:ci_build, :failed, :test_reports_with_duplicate_failed_test_names, pipeline: pipeline, project: project) + create(:ci_build, :failed, :test_reports_with_duplicate_failed_test_names, pipeline: pipeline) end it 'does not fail but does not persist duplicate data' do @@ -95,8 +106,8 @@ RSpec.describe Ci::TestFailureHistoryService, :aggregate_failures do context 'when pipeline has no failed builds with test reports' do before do - create(:ci_build, :test_reports, pipeline: pipeline, project: project) - create(:ci_build, :failed, pipeline: pipeline, project: project) + create(:ci_build, :test_reports, pipeline: pipeline) + create(:ci_build, :failed, pipeline: pipeline) end it 'does not persist data' do @@ -109,14 +120,10 @@ RSpec.describe Ci::TestFailureHistoryService, :aggregate_failures do end describe '#should_track_failures?' do - let(:project) { create(:project, :repository) } - let(:pipeline) { create(:ci_empty_pipeline, status: :created, project: project, ref: project.default_branch) } - subject { described_class.new(pipeline).should_track_failures? } - before do - create(:ci_build, :test_reports, :failed, pipeline: pipeline, project: project) - create(:ci_build, :test_reports, :failed, pipeline: pipeline, project: project) + let_it_be(:jobs) do + create_list(:ci_build, 2, :test_reports, :failed, pipeline: pipeline) end context 'when feature flag is enabled and pipeline ref is the default branch' do |