spec/lib/flapjack/coordinator_spec.rb in flapjack-0.7.14 vs spec/lib/flapjack/coordinator_spec.rb in flapjack-0.7.15

- old
+ new

@@ -9,10 +9,12 @@ let(:logger) { mock(Logger) } let(:stdout_out) { mock('stdout_out') } let(:syslog_out) { mock('syslog_out') } + let!(:time) { Time.now } + def setup_logger formatter = mock('Formatter') Log4r::PatternFormatter.should_receive(:new).with( :pattern => "%d [%l] :: flapjack-coordinator :: %m", :date_pattern => "%Y-%m-%dT%H:%M:%S%z").and_return(formatter) @@ -39,13 +41,16 @@ executive.should_receive(:start) executive.should_receive(:stop) executive.should_receive(:update_status) executive.should_receive(:status).exactly(3).times.and_return('stopped') + Time.should_receive(:now).and_return(time) + fc = Flapjack::Coordinator.new(config) Flapjack::Pikelet.should_receive(:create).with('executive', - :config => cfg['executive'], :redis_config => {}).and_return(executive) + :config => cfg['executive'], :redis_config => {}, :boot_time => time). + and_return(executive) fiber.should_receive(:resume) Fiber.should_receive(:new).and_yield.and_return(fiber) EM.should_receive(:stop) @@ -67,13 +72,16 @@ executive.should_receive(:start).and_raise(RuntimeError) executive.should_receive(:stop) executive.should_receive(:update_status) executive.should_receive(:status).exactly(3).times.and_return('stopped') + Time.should_receive(:now).and_return(time) + fc = Flapjack::Coordinator.new(config) Flapjack::Pikelet.should_receive(:create).with('executive', - :config => cfg['executive'], :redis_config => {}).and_return(executive) + :config => cfg['executive'], :redis_config => {}, :boot_time => time) + .and_return(executive) fiber.should_receive(:resume) Fiber.should_receive(:new).and_yield.and_return(fiber) EM.should_receive(:stop) @@ -138,19 +146,22 @@ executive.should_receive(:stop) executive.should_receive(:update_status) executive.should_receive(:status).exactly(3).times.and_return('stopped') jabber = mock('jabber') - Flapjack::Pikelet.should_receive(:create).with('jabber', - :config => {"enabled" => "yes"}, :redis_config => {}).and_return(jabber) + Flapjack::Pikelet.should_receive(:create). + with('jabber', :config => {"enabled" => "yes"}, :redis_config => {}, + :boot_time => time). + and_return(jabber) jabber.should_receive(:start) fiber.should_receive(:resume) Fiber.should_receive(:new).and_yield.and_return(fiber) config.should_receive(:for_redis).and_return({}) fc = Flapjack::Coordinator.new(config) + fc.instance_variable_set('@boot_time', time) fc.instance_variable_set('@pikelets', [executive]) fc.reload fc.instance_variable_get('@pikelets').should == [jabber] end @@ -176,10 +187,11 @@ executive.should_receive(:reload).with(new_cfg['executive']).and_return(true) executive.should_not_receive(:stop) config.should_receive(:for_redis).and_return({}) fc = Flapjack::Coordinator.new(config) + fc.instance_variable_set('@boot_time', time) fc.instance_variable_set('@pikelets', [executive]) fc.reload fc.instance_variable_get('@pikelets').should == [executive] end @@ -211,14 +223,16 @@ new_exec = mock('new_executive') new_exec.should_receive(:start) Flapjack::Pikelet.should_receive(:create). - with('executive', :config => new_cfg['executive'], :redis_config => {}). + with('executive', :config => new_cfg['executive'], :redis_config => {}, + :boot_time => time). and_return(new_exec) config.should_receive(:for_redis).and_return({}) fc = Flapjack::Coordinator.new(config) + fc.instance_variable_set('@boot_time', time) fc.instance_variable_set('@pikelets', [executive]) fc.reload fc.instance_variable_get('@pikelets').should == [new_exec] end