rearrange and refactor specs to make more sense

This commit is contained in:
Anuj Biyani 2013-06-03 18:07:10 -07:00
parent b463901f98
commit 55e60a989e
3 changed files with 49 additions and 39 deletions

View File

@ -1,5 +1,5 @@
class AwsHaRelease class AwsHaRelease
attr_reader :max_size_change attr_reader :group
def initialize(opts) def initialize(opts)
AWS.config(access_key_id: opts[:aws_access_key], secret_access_key: opts[:aws_secret_key], region: opts[:region]) AWS.config(access_key_id: opts[:aws_access_key], secret_access_key: opts[:aws_secret_key], region: opts[:region])
@ -20,7 +20,7 @@ class AwsHaRelease
if @group.max_size == @group.desired_capacity if @group.max_size == @group.desired_capacity
@group.update(max_size: @group.max_size + 1) @group.update(max_size: @group.max_size + 1)
@max_size_change += 1 @max_size_change = 1
end end
@group.update(desired_capacity: @group.desired_capacity + 1) @group.update(desired_capacity: @group.desired_capacity + 1)
@ -39,6 +39,7 @@ class AwsHaRelease
if @max_size_change > 0 if @max_size_change > 0
@group.update(max_size: @group.max_size - @max_size_change) @group.update(max_size: @group.max_size - @max_size_change)
@max_size_change = 0
end end
@group.resume_all_processes @group.resume_all_processes

View File

@ -43,23 +43,29 @@ describe 'aws-ha-release' do
@aws_ha_release.execute! @aws_ha_release.execute!
end end
it 'adjusts the maximum size if the desired capacity is equal to it' do it 'adjusts the max size as well as the desired capacity if the desired capacity is equal to it' do
@group.update(max_size: 1, desired_capacity: 1) @group.update(max_size: 1, desired_capacity: 1)
expect(@aws_ha_release.max_size_change).to eq 0
@aws_ha_release.group.should_receive(:update).with(max_size: 2).ordered.and_call_original
@aws_ha_release.group.should_receive(:update).with(desired_capacity: 2).ordered.and_call_original
@aws_ha_release.group.should_receive(:update).with(desired_capacity: 1).ordered.and_call_original
@aws_ha_release.group.should_receive(:update).with(max_size: 1).ordered.and_call_original
@aws_ha_release.execute! @aws_ha_release.execute!
expect(@group.max_size).to eq 2
expect(@aws_ha_release.max_size_change).to eq 1
end end
it 'increases the desired capacity by 1' do it 'only adjusts the desired capacity if max size does not equal desired capacity' do
@aws_ha_release.group.should_receive(:update).with(desired_capacity: 2).ordered.and_call_original
@aws_ha_release.group.should_receive(:update).with(desired_capacity: 1).ordered.and_call_original
@aws_ha_release.execute! @aws_ha_release.execute!
end
expect(@group.desired_capacity).to eq 2 end
describe 'determining if instances are in service' do
before do
@group = as.groups.create opts[:as_group_name]
@aws_ha_release = AwsHaRelease.new(opts)
end end
context 'determining if instances are in service' do
it 'checks all instances across a given load balancer' do it 'checks all instances across a given load balancer' do
load_balancer = AWS::FakeELB::LoadBalancer.new 'test_load_balancer_01' load_balancer = AWS::FakeELB::LoadBalancer.new 'test_load_balancer_01'
@ -99,7 +105,6 @@ describe 'aws-ha-release' do
expect(@aws_ha_release.all_instances_inservice?(load_balancers)).to eq true expect(@aws_ha_release.all_instances_inservice?(load_balancers)).to eq true
end end
end end
end
describe '#deregister_instance' do describe '#deregister_instance' do
before do before do

View File

@ -37,6 +37,10 @@ module AWS
end end
end end
def resume_all_processes
@suspended_processes.clear
end
def update(options = {}) def update(options = {})
options.each do |key, value| options.each do |key, value|
self.instance_variable_set "@#{key}", value self.instance_variable_set "@#{key}", value