#376: added specs

This commit is contained in:
Vokhmin Alexey V 2014-04-18 00:18:24 +04:00
parent 16f2bbb246
commit 602df4e57a
6 changed files with 66 additions and 1 deletions

View File

@ -3,7 +3,7 @@ class RestartNodesJob
def self.perform
return if NodeInstruction.all_locked?
available_nodes = RpmBuildNode.all.map{ |n| n.user_id }.compact.uniq
available_nodes = RpmBuildNode.all.map{ |n| n.user_id if n.user.try(:system?) }.compact.uniq
NodeInstruction.where(status: NodeInstruction::READY).
where.not(user_id: available_nodes).find_each(&:restart)
end

View File

@ -0,0 +1,6 @@
FactoryGirl.define do
factory :node_instruction do
association :user, factory: :system_user
instruction { FactoryGirl.generate(:string) }
end
end

View File

@ -0,0 +1,6 @@
FactoryGirl.define do
factory :rpm_build_node do
id { FactoryGirl.generate(:string) }
user_id { FactoryGirl.create(:user).id }
end
end

View File

@ -12,4 +12,8 @@ FactoryGirl.define do
factory :admin, parent: :user do
role 'admin'
end
factory :system_user, parent: :user do
role 'system'
end
end

View File

@ -0,0 +1,40 @@
require 'spec_helper'
describe RestartNodesJob do
it 'ensures that not raises error' do
lambda do
RestartNodesJob.perform
end.should_not raise_exception
end
it 'ensures that do nothing when all instructions disabled' do
NodeInstruction.lock_all
expect(RpmBuildNode).to_not receive(:all)
RestartNodesJob.perform
end
it 'ensures that creates tasks' do
allow_any_instance_of(NodeInstruction).to receive(:perform_restart)
# ABF active node
ni1 = FactoryGirl.create(:node_instruction)
FactoryGirl.create(:rpm_build_node, user_id: ni1.user_id)
# User node
FactoryGirl.create(:rpm_build_node)
FactoryGirl.create(:node_instruction, status: NodeInstruction::DISABLED)
ni2 = FactoryGirl.create(:node_instruction, status: NodeInstruction::RESTARTING)
FactoryGirl.create(:node_instruction, status: NodeInstruction::FAILED)
ni3 = FactoryGirl.create(:node_instruction)
RestartNodesJob.perform
NodeInstruction.where(status: NodeInstruction::RESTARTING).should have(2).items
NodeInstruction.where(status: NodeInstruction::RESTARTING).should include(ni2, ni3)
NodeInstruction.where(status: NodeInstruction::RESTARTING).should_not include(ni1)
end
end

View File

@ -0,0 +1,9 @@
require 'spec_helper'
describe NodeInstruction do
it 'is valid given valid attributes' do
FactoryGirl.build(:node_instruction).should be_valid
end
end