Commit 6c3ddc14 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix/gb/fix-build-log-crc32-checksum-base' into 'master'

Parse build trace checksum provided in hexadecimal

Closes #258636

See merge request gitlab-org/gitlab!43718
parents ff1b2e87 00686859
...@@ -9,4 +9,10 @@ class Ci::BuildPendingState < ApplicationRecord ...@@ -9,4 +9,10 @@ class Ci::BuildPendingState < ApplicationRecord
enum failure_reason: CommitStatus.failure_reasons enum failure_reason: CommitStatus.failure_reasons
validates :build, presence: true validates :build, presence: true
def crc32
trace_checksum.try do |checksum|
checksum.to_s.split('crc32:').last.to_i(16)
end
end
end end
...@@ -24,17 +24,13 @@ module Gitlab ...@@ -24,17 +24,13 @@ module Gitlab
end end
def valid? def valid?
return false unless state_crc32 > 0 return false unless state_crc32.present?
state_crc32 == chunks_crc32 state_crc32 == chunks_crc32
end end
def state_crc32 def state_crc32
strong_memoize(:crc32) do strong_memoize(:crc32) { build.pending_state&.crc32 }
build.pending_state&.trace_checksum.then do |checksum|
checksum.to_s.split('crc32:').last.to_i
end
end
end end
def chunks_crc32 def chunks_crc32
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
FactoryBot.define do FactoryBot.define do
factory :ci_build_pending_state, class: 'Ci::BuildPendingState' do factory :ci_build_pending_state, class: 'Ci::BuildPendingState' do
build factory: :ci_build build factory: :ci_build
trace_checksum { 'crc32:12345678' } trace_checksum { 'crc32:bc614e' }
state { 'success' } state { 'success' }
end end
end end
...@@ -9,7 +9,7 @@ RSpec.describe Gitlab::Ci::Trace::Checksum do ...@@ -9,7 +9,7 @@ RSpec.describe Gitlab::Ci::Trace::Checksum do
context 'when build pending state exists' do context 'when build pending state exists' do
before do before do
create(:ci_build_pending_state, build: build, trace_checksum: 'crc32:3564598592') create(:ci_build_pending_state, build: build, trace_checksum: 'crc32:d4777540')
end end
context 'when matching persisted trace chunks exist' do context 'when matching persisted trace chunks exist' do
...@@ -70,8 +70,8 @@ RSpec.describe Gitlab::Ci::Trace::Checksum do ...@@ -70,8 +70,8 @@ RSpec.describe Gitlab::Ci::Trace::Checksum do
context 'when build pending state is missing' do context 'when build pending state is missing' do
describe '#state_crc32' do describe '#state_crc32' do
it 'returns zero' do it 'returns nil' do
expect(subject.state_crc32).to be_zero expect(subject.state_crc32).to be_nil
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::BuildPendingState do
describe '#crc32' do
context 'when checksum does not exist' do
let(:pending_state) do
build(:ci_build_pending_state, trace_checksum: nil)
end
it 'returns nil' do
expect(pending_state.crc32).to be_nil
end
end
context 'when checksum is in hexadecimal' do
let(:pending_state) do
build(:ci_build_pending_state, trace_checksum: 'crc32:75bcd15')
end
it 'returns decimal representation of the checksum' do
expect(pending_state.crc32).to eq 123456789
end
end
end
end
...@@ -125,7 +125,7 @@ RSpec.describe Ci::UpdateBuildStateService do ...@@ -125,7 +125,7 @@ RSpec.describe Ci::UpdateBuildStateService do
end end
context 'when trace checksum is valid' do context 'when trace checksum is valid' do
let(:params) { { checksum: 'crc32:3984772369', state: 'success' } } let(:params) { { checksum: 'crc32:ed82cd11', state: 'success' } }
it 'does not increment invalid trace metric' do it 'does not increment invalid trace metric' do
execute_with_stubbed_metrics! execute_with_stubbed_metrics!
......
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