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
enum failure_reason: CommitStatus.failure_reasons
validates :build, presence: true
def crc32
trace_checksum.try do |checksum|
checksum.to_s.split('crc32:').last.to_i(16)
end
end
end
......@@ -24,17 +24,13 @@ module Gitlab
end
def valid?
return false unless state_crc32 > 0
return false unless state_crc32.present?
state_crc32 == chunks_crc32
end
def state_crc32
strong_memoize(:crc32) do
build.pending_state&.trace_checksum.then do |checksum|
checksum.to_s.split('crc32:').last.to_i
end
end
strong_memoize(:crc32) { build.pending_state&.crc32 }
end
def chunks_crc32
......
......@@ -3,7 +3,7 @@
FactoryBot.define do
factory :ci_build_pending_state, class: 'Ci::BuildPendingState' do
build factory: :ci_build
trace_checksum { 'crc32:12345678' }
trace_checksum { 'crc32:bc614e' }
state { 'success' }
end
end
......@@ -9,7 +9,7 @@ RSpec.describe Gitlab::Ci::Trace::Checksum do
context 'when build pending state exists' 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
context 'when matching persisted trace chunks exist' do
......@@ -70,8 +70,8 @@ RSpec.describe Gitlab::Ci::Trace::Checksum do
context 'when build pending state is missing' do
describe '#state_crc32' do
it 'returns zero' do
expect(subject.state_crc32).to be_zero
it 'returns nil' do
expect(subject.state_crc32).to be_nil
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
end
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
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