Commit e844f5a5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add specs for creating and removing build runtime metadata

parent 85def17c
...@@ -300,7 +300,7 @@ module Ci ...@@ -300,7 +300,7 @@ module Ci
end end
# rubocop:disable CodeReuse/ServiceClass # rubocop:disable CodeReuse/ServiceClass
after_transition any: :pending do |build, transition| after_transition any => [:pending] do |build, transition|
Ci::UpdateBuildQueueService.new.push(build, transition) Ci::UpdateBuildQueueService.new.push(build, transition)
build.run_after_commit do build.run_after_commit do
...@@ -312,11 +312,11 @@ module Ci ...@@ -312,11 +312,11 @@ module Ci
Ci::UpdateBuildQueueService.new.pop(build, transition) Ci::UpdateBuildQueueService.new.pop(build, transition)
end end
after_transition any: :running do |build, transition| after_transition any => [:running] do |build, transition|
Ci::UpdateBuildQueueService.new.track(build, transition) Ci::UpdateBuildQueueService.new.track(build, transition)
end end
after_transition running: any do |build| after_transition running: any do |build, transition|
Ci::UpdateBuildQueueService.new.untrack(build, transition) Ci::UpdateBuildQueueService.new.untrack(build, transition)
Ci::BuildRunnerSession.where(build: build).delete_all Ci::BuildRunnerSession.where(build: build).delete_all
...@@ -1095,9 +1095,7 @@ module Ci ...@@ -1095,9 +1095,7 @@ module Ci
end end
def shared_runner_build? def shared_runner_build?
return false if runner.nil? runner&.instance_type?
runner.instance_type?
end end
protected protected
......
...@@ -11,7 +11,7 @@ module Ci ...@@ -11,7 +11,7 @@ module Ci
enum runner_type: ::Ci::Runner.runner_types enum runner_type: ::Ci::Runner.runner_types
def self.upsert_shared_runner_build!(build) def self.upsert_shared_runner_build!(build)
unless build.runner && build.runner.instance_type? unless build.shared_runner_build?
raise ArgumentError, 'build has not been picked by a shared runner' raise ArgumentError, 'build has not been picked by a shared runner'
end end
......
...@@ -493,6 +493,34 @@ RSpec.describe Ci::Build do ...@@ -493,6 +493,34 @@ RSpec.describe Ci::Build do
expect(build.queuing_entry).to be_present expect(build.queuing_entry).to be_present
end end
end end
context 'when build has been picked by a shared runner' do
let(:build) { create(:ci_build, :pending) }
it 'creates runtime metadata entry' do
build.runner = create(:ci_runner, :instance_type)
build.run!
expect(build.reload.runtime_metadata).to be_present
end
end
end
describe '#drop' do
context 'when has a runtime tracking entry' do
let(:build) { create(:ci_build, :pending) }
it 'removes runtime tracking entry' do
build.runner = create(:ci_runner, :instance_type)
build.run!
expect(build.reload.runtime_metadata).to be_present
build.drop!
expect(build.reload.runtime_metadata).not_to be_present
end
end
end end
describe '#schedulable?' do describe '#schedulable?' do
...@@ -5179,4 +5207,34 @@ RSpec.describe Ci::Build do ...@@ -5179,4 +5207,34 @@ RSpec.describe Ci::Build do
it { expect(matcher.project).to eq(build.project) } it { expect(matcher.project).to eq(build.project) }
end end
describe '#shared_runner_build?' do
context 'when build does not have a runner assigned' do
it 'is not a shared runner build' do
expect(build.runner).to be_nil
expect(build).not_to be_shared_runner_build
end
end
context 'when build has a project runner assigned' do
before do
build.runner = create(:ci_runner, :project)
end
it 'is not a shared runner build' do
expect(build).not_to be_shared_runner_build
end
end
context 'when build has an instance runner assigned' do
before do
build.runner = create(:ci_runner, :instance_type)
end
it 'is a shared runner build' do
expect(build).to be_shared_runner_build
end
end
end
end end
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