spec/heroku/scalr/app_spec.rb in heroku-scalr-0.2.4 vs spec/heroku/scalr/app_spec.rb in heroku-scalr-0.3.0
- old
+ new
@@ -1,10 +1,10 @@
require 'spec_helper'
describe Heroku::Scalr::App do
- subject { described_class.new('name', api_key: 'key', max_dynos: 3) }
+ subject { described_class.new('name', api_key: 'key', max_dynos: 3, heat_freq: 30) }
def mock_response(status, body)
mock "APIResponse", status: status, headers: {}, body: body
end
@@ -18,11 +18,12 @@
its(:max_dynos) { should be(3) }
its(:wait_low) { should be(10) }
its(:wait_high) { should be(100) }
its(:ping_low) { should be(200) }
its(:ping_high) { should be(500) }
- its(:min_frequency) { should be(60) }
+ its(:heat_freq) { should be(30) }
+ its(:cool_freq) { should be(180) }
its(:last_scaled_at) { should == Time.at(0)}
describe "failures" do
it "should raise error when there's no API key" do
@@ -80,32 +81,46 @@
end
context "down" do
it "should return the new number of dynos" do
+ subject.instance_variable_set :@last_scaled_at, (Time.now - 185)
mock_api.should_receive(:post_ps_scale).with("name", "web", 1).and_return mock_response(200, "")
subject.scale!.should == 1
end
it "should skip if min number of dynos reached" do
mock_api.should_receive(:get_app).with("name").and_return mock_response(200, { "dynos" => 1 })
mock_api.should_not_receive(:post_ps_scale)
subject.scale!.should be_nil
end
+ it "should skip if scaled too recently" do
+ subject.instance_variable_set :@last_scaled_at, (Time.now - 175)
+ mock_api.should_not_receive(:post_ps_scale)
+ subject.scale!.should be_nil
+ end
+
end
context "up" do
before { subject.metric.stub by: 1 }
it "should return the new number of dynos" do
+ subject.instance_variable_set :@last_scaled_at, (Time.now - 35)
mock_api.should_receive(:post_ps_scale).with("name", "web", 3).and_return mock_response(200, "")
subject.scale!.should == 3
end
it "should skip if max number of dynos reached" do
mock_api.should_receive(:get_app).with("name").and_return mock_response(200, { "dynos" => 3 })
+ mock_api.should_not_receive(:post_ps_scale)
+ subject.scale!.should be_nil
+ end
+
+ it "should skip if scaled too recently" do
+ subject.instance_variable_set :@last_scaled_at, (Time.now - 25)
mock_api.should_not_receive(:post_ps_scale)
subject.scale!.should be_nil
end
end
\ No newline at end of file