Skip to content
Snippets Groups Projects
Unverified Commit 31af6be0 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Fix specs

parent 1c7eb963
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -22,7 +22,7 @@ module Ci
scope :online, ->() { where('contacted_at > ?', LAST_CONTACT_TIME) }
scope :ordered, ->() { order(id: :desc) }
 
after_save :tick_runner_queue
after_save :tick_runner_queue, if: :form_editable_changed?
 
scope :owned_or_shared, ->(project_id) do
joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id')
Loading
Loading
@@ -126,14 +126,14 @@ module Ci
end
 
def tick_runner_queue
new_update = Time.new.inspect
new_update = SecureRandom.hex
Gitlab::Redis.with { |redis| redis.set(runner_queue_key, new_update, ex: RUNNER_QUEUE_EXPIRY_TIME) }
new_update
end
 
def ensure_runner_queue_value
Gitlab::Redis.with do |redis|
value = Time.new.inspect
value = SecureRandom.hex
redis.set(runner_queue_key, value, ex: RUNNER_QUEUE_EXPIRY_TIME, nx: true)
redis.get(runner_queue_key)
end
Loading
Loading
@@ -149,6 +149,12 @@ module Ci
"runner:build_queue:#{self.token}"
end
 
def form_editable_changed?
FORM_EDITABLE.any? do |editable|
public_send("#{editable}_changed?")
end
end
def tag_constraints
unless has_tags? || run_untagged?
errors.add(:tags_list,
Loading
Loading
module Ci
class UpdateBuildQueueService
def execute(build)
build.project.runners.select do |runner|
build.project.runners.each do |runner|
if runner.can_pick?(build)
runner.tick_runner_queue
end
Loading
Loading
Loading
Loading
@@ -226,7 +226,7 @@ module API
end
 
def render_api_error!(message, status)
error!({ 'message' => message }, status, header)
error!({ 'message' => message }, status)
end
 
def handle_api_exception(exception)
Loading
Loading
Loading
Loading
@@ -277,21 +277,44 @@ describe Ci::Runner, models: true do
it 'sets a new last_update value when it is called the first time' do
last_update = runner.ensure_runner_queue_value
 
expect_value_in_redis(last_update)
expect_value_in_redis.to eq(last_update)
end
 
it 'does not change if it is not expired and called again' do
last_update = runner.ensure_runner_queue_value
 
expect(runner.ensure_runner_queue_value).to eq(last_update)
expect_value_in_redis(last_update)
expect_value_in_redis.to eq(last_update)
end
 
def expect_value_in_redis(last_update)
context 'updates runner queue after changing editable value' do
let!(:last_update) { runner.ensure_runner_queue_value }
before do
runner.update(description: 'new runner')
end
it 'sets a new last_update value' do
expect_value_in_redis.not_to eq(last_update)
end
end
context 'does not update runner value after save' do
let!(:last_update) { runner.ensure_runner_queue_value }
before do
runner.touch
end
it 'has an old last_update value' do
expect_value_in_redis.to eq(last_update)
end
end
def expect_value_in_redis
Gitlab::Redis.with do |redis|
runner_queue_key = runner.send(:runner_queue_key)
expect(redis.get(runner_queue_key)).to eq(last_update)
expect(redis.get(runner_queue_key))
end
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment