Skip to content

Commit

Permalink
Fix specs to handle extra server creation when podified
Browse files Browse the repository at this point in the history
In specs we often will create a server, which creates a zone for
us in the factory. Previously, even when we were simulating running
in pods, that would leave us with one server and one zone.

Now, the zone creation process is checking the environment for
podified and creating a server itself. This leaves us with an
extra call to MiqEnvironment::Command.is_podified and some bonus
server records.

This commit handles both of those issues.
  • Loading branch information
carbonin committed Jan 27, 2020
1 parent cdfa519 commit 3fdfb86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
16 changes: 9 additions & 7 deletions spec/lib/workers/evm_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,21 @@
expect(subject.servers_to_monitor.first.id).to eq(MiqServer.first.id)

4.times { FactoryBot.create(:miq_server) }
expect(subject).to receive(:impersonate_server).exactly(4).times
expect(subject).to receive(:start_server).exactly(4).times

num_servers = MiqServer.count

# one for each new server
expect(subject).to receive(:impersonate_server).exactly(num_servers - 1).times
expect(subject).to receive(:start_server).exactly(num_servers - 1).times
subject.refresh_servers_to_monitor

expect(subject.servers_to_monitor.count).to eq(5)
expect(subject.servers_to_monitor.count).to eq(num_servers)
expect(subject.servers_to_monitor.map(&:id)).to match_array(MiqServer.all.map(&:id))
end

it "removes a server when it is removed from the database" do
server = FactoryBot.create(:miq_server)
expect(subject.servers_to_monitor.map(&:id)).to include(server.id)
expect(subject.servers_to_monitor.count).to eq(2)

monitor_server = subject.servers_to_monitor.find { |s| s.id == server.id }
expect(monitor_server).to receive(:shutdown)
Expand All @@ -75,7 +78,6 @@
subject.refresh_servers_to_monitor

expect(subject.servers_to_monitor.map(&:id)).not_to include(server.id)
expect(subject.servers_to_monitor.count).to eq(1)
end

# Note: this is a very important spec
Expand All @@ -86,8 +88,8 @@
initial_object_id = subject.servers_to_monitor.first.object_id

4.times { FactoryBot.create(:miq_server) }
expect(subject).to receive(:impersonate_server).exactly(4).times
expect(subject).to receive(:start_server).exactly(4).times
allow(subject).to receive(:impersonate_server)
allow(subject).to receive(:start_server)
subject.refresh_servers_to_monitor

new_objects = subject.servers_to_monitor.map(&:object_id)
Expand Down
10 changes: 5 additions & 5 deletions spec/models/miq_server/queue_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@

describe "#ntp_reload_queue" do
it "enqueues a message if the server is an appliance, but not a container" do
expect(MiqEnvironment::Command).to receive(:is_appliance?).and_return(true)
expect(MiqEnvironment::Command).to receive(:is_container?).and_return(false)
allow(MiqEnvironment::Command).to receive(:is_appliance?).and_return(true)
allow(MiqEnvironment::Command).to receive(:is_container?).and_return(false)

server.ntp_reload_queue

expect(ntp_reload_enqueued?).to be_truthy
end

it "doesn't enqueue a message if the server is not an appliance" do
expect(MiqEnvironment::Command).to receive(:is_appliance?).and_return(false)
allow(MiqEnvironment::Command).to receive(:is_appliance?).and_return(false)

server.ntp_reload_queue

expect(ntp_reload_enqueued?).to be_falsey
end

it "doesn't enqueue a message if the server is a container" do
expect(MiqEnvironment::Command).to receive(:is_appliance?).and_return(true)
expect(MiqEnvironment::Command).to receive(:is_container?).and_return(true)
allow(MiqEnvironment::Command).to receive(:is_appliance?).and_return(true)
allow(MiqEnvironment::Command).to receive(:is_container?).and_return(true)

server.ntp_reload_queue

Expand Down

0 comments on commit 3fdfb86

Please sign in to comment.