Commit 11ee48f3 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix failures

parent cba9eeb6
...@@ -24,13 +24,13 @@ module Ci ...@@ -24,13 +24,13 @@ module Ci
def status def status
strong_memoize(:status) do strong_memoize(:status) do
if Feature.enabled?(:ci_composite_status, default_enabled: false) if Feature.enabled?(:ci_composite_status, default_enabled: false)
all_statuses = @jobs.pluck(:status, :allow_failure)
Gitlab::Ci::Status::Composite Gitlab::Ci::Status::Composite
.new(all_statuses, status_key: 0, allow_failure_key: 1) .new(@jobs)
.status .status
else else
CommitStatus.where(id: @jobs).legacy_status CommitStatus
.where(id: @jobs)
.legacy_status
end end
end end
end end
......
...@@ -14,7 +14,8 @@ module Ci ...@@ -14,7 +14,8 @@ module Ci
@pipeline = pipeline @pipeline = pipeline
@name = name @name = name
@status = status @status = status
@warnings = warnings # support ints and booleans
@has_warnings = ActiveRecord::Type::Boolean.new.cast(warnings)
end end
def groups def groups
...@@ -52,14 +53,12 @@ module Ci ...@@ -52,14 +53,12 @@ module Ci
end end
def has_warnings? def has_warnings?
case @warnings # lazilly calculate the warnings
when Integer if @has_warnings.nil?
@warnings > 0 @has_warnings = statuses.latest.failed_but_allowed.any?
when TrueClass, FalseClass
@warnings
else
statuses.latest.failed_but_allowed.any?
end end
@has_warnings
end end
def manual_playable? def manual_playable?
......
...@@ -411,10 +411,8 @@ module Ci ...@@ -411,10 +411,8 @@ module Ci
.group_by(&:stage) .group_by(&:stage)
stages.map do |stage_name, jobs| stages.map do |stage_name, jobs|
jobs_statuses = jobs.pluck(:status, :allow_failure)
composite_status = Gitlab::Ci::Status::Composite composite_status = Gitlab::Ci::Status::Composite
.new(jobs_statuses, status_key: 0, allow_failure_key: 1) .new(jobs)
Ci::LegacyStage.new(self, Ci::LegacyStage.new(self,
name: stage_name, name: stage_name,
......
...@@ -65,13 +65,8 @@ module HasStatus ...@@ -65,13 +65,8 @@ module HasStatus
# 2. Or executes expensive SQL query # 2. Or executes expensive SQL query
def slow_composite_status def slow_composite_status
if Feature.enabled?(:ci_composite_status, default_enabled: false) if Feature.enabled?(:ci_composite_status, default_enabled: false)
columns = [:status]
columns << :allow_failure if column_names.include?('allow_failure')
all_statuses = all.pluck(*columns)
Gitlab::Ci::Status::Composite Gitlab::Ci::Status::Composite
.new(all_statuses, status_key: 0, allow_failure_key: 1) .new(all, with_allow_failure: columns_hash.key?('allow_failure'))
.status .status
else else
legacy_status legacy_status
......
...@@ -6,15 +6,15 @@ module Gitlab ...@@ -6,15 +6,15 @@ module Gitlab
class Composite class Composite
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
# This class accepts an array of arrays # This class accepts an array of arrays/hashes/or objects
# The `status_key` and `allow_failure_key` define an index def initialize(all_statuses, with_allow_failure: true)
# or key in each entry unless all_statuses.respond_to?(:pluck)
def initialize(all_statuses, status_key:, allow_failure_key:) raise ArgumentError, "all_statuses needs to respond to `.pluck`"
raise ArgumentError, "all_statuses needs to be an Array" unless all_statuses.is_a?(Array) end
@status_set = Set.new @status_set = Set.new
@status_key = status_key @status_key = 0
@allow_failure_key = allow_failure_key @allow_failure_key = 1 if with_allow_failure
consume_all_statuses(all_statuses) consume_all_statuses(all_statuses)
end end
...@@ -78,7 +78,13 @@ module Gitlab ...@@ -78,7 +78,13 @@ module Gitlab
end end
def consume_all_statuses(all_statuses) def consume_all_statuses(all_statuses)
all_statuses.each(&method(:consume_status)) columns = []
columns[@status_key] = :status
columns[@allow_failure_key] = :allow_failure if @allow_failure_key
all_statuses
.pluck(*columns)
.each(&method(:consume_status))
end end
def consume_status(description) def consume_status(description)
......
...@@ -14,11 +14,12 @@ describe Gitlab::Ci::Status::Composite do ...@@ -14,11 +14,12 @@ describe Gitlab::Ci::Status::Composite do
end end
describe '#status' do describe '#status' do
subject { composite_status.status }
shared_examples 'compares composite with SQL status' do shared_examples 'compares composite with SQL status' do
it 'returns exactly the same result' do it 'returns exactly the same result' do
is_expected.to eq(Ci::Build.where(id: all_statuses).legacy_status) builds = Ci::Build.where(id: all_statuses)
expect(composite_status.status).to eq(builds.legacy_status)
expect(composite_status.warnings?).to eq(builds.failed_but_allowed.any?)
end end
end end
...@@ -31,11 +32,7 @@ describe Gitlab::Ci::Status::Composite do ...@@ -31,11 +32,7 @@ describe Gitlab::Ci::Status::Composite do
end end
let(:composite_status) do let(:composite_status) do
described_class.new( described_class.new(all_statuses)
all_statuses.pluck(:status),
status_key: 0,
allow_failure_key: nil
)
end end
end end
...@@ -48,11 +45,7 @@ describe Gitlab::Ci::Status::Composite do ...@@ -48,11 +45,7 @@ describe Gitlab::Ci::Status::Composite do
end end
let(:composite_status) do let(:composite_status) do
described_class.new( described_class.new(all_statuses)
all_statuses.pluck(:status, :allow_failure),
status_key: 0,
allow_failure_key: 1
)
end end
end end
end end
......
...@@ -232,15 +232,6 @@ describe Ci::LegacyStage do ...@@ -232,15 +232,6 @@ describe Ci::LegacyStage do
expect(stage).not_to have_warnings expect(stage).not_to have_warnings
end end
end end
context 'when number of warnings is not a valid value' do
let(:stage) { build(:ci_stage, warnings: 'aa') }
it 'calculates statuses using database queries' do
expect(stage).to receive(:statuses).and_call_original
expect(stage).not_to have_warnings
end
end
end end
context 'when calculating warnings from statuses' do context 'when calculating warnings from statuses' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment