40 lines
1.7 KiB
Ruby
40 lines
1.7 KiB
Ruby
require 'workers/stack_bootstrap/servers_bootstrapper'
|
|
|
|
RSpec.describe ServersBootstrapper, stubbed_connector: true, init_messages: true do
|
|
let(:out) { double(:out, puts: nil, flush: nil) }
|
|
let(:jid) { 1000 }
|
|
let(:servers) { [build(:server, id: 'a'), build(:server, id: 'b')] }
|
|
let(:bootstrapper) { described_class.new(out, jid, servers ) }
|
|
let(:bootstrap_job_ids) { %w(100 200) }
|
|
|
|
describe '#bootstrap_group' do
|
|
before do
|
|
allow(Worker).to receive(:start_async).and_return(*bootstrap_job_ids)
|
|
allow(stubbed_connector).to receive(:add_report_subreports)
|
|
allow(stubbed_connector).to receive(:report)
|
|
allow_any_instance_of(JobWaiter).to receive(:wait) { 0 }
|
|
end
|
|
|
|
it 'start bootstrap workers and add subreports' do
|
|
expect(Worker).to receive(:start_async).with(BootstrapWorker, hash_including(:server_attrs, :bootstrap_template, :owner))
|
|
expect(stubbed_connector).to receive(:add_report_subreports).with(jid, bootstrap_job_ids)
|
|
bootstrapper.bootstrap_group
|
|
end
|
|
|
|
it 'returns :ok result if everything ok' do
|
|
expect( bootstrapper.bootstrap_group.first.reason ).to eq :ok
|
|
end
|
|
|
|
it 'returns proper error results' do
|
|
waiter = instance_double(JobWaiter)
|
|
allow(waiter).to receive(:wait).and_return(2, 8)
|
|
allow(JobWaiter).to receive(:new) { waiter }
|
|
expect( bootstrapper.bootstrap_group.map(&:reason) ).to eq [:bootstrap_error, :deploy_error]
|
|
end
|
|
|
|
it "returns :timeout_reached result if bootstrap and deploy hasn't been finished in 5000 seconds" do
|
|
allow_any_instance_of(JobWaiter).to receive(:wait) { raise JobWaiter::TimeoutReached }
|
|
expect( bootstrapper.bootstrap_group.first.reason ).to eq :timeout_reached
|
|
end
|
|
end
|
|
end |