spec/lib/flapjack/coordinator_spec.rb in flapjack-0.8.1 vs spec/lib/flapjack/coordinator_spec.rb in flapjack-0.8.2

- old
+ new

@@ -27,23 +27,22 @@ expect(Time).to receive(:now).and_return(time) fc = Flapjack::Coordinator.new(config) expect(Flapjack::Pikelet).to receive(:create).with('processor', - :config => cfg['processor'], :redis_config => {}, :boot_time => time, :coordinator => fc). + :config => cfg['processor'], :redis_config => {}, :boot_time => time). and_return(processor) - expect(fiber).to receive(:resume) - expect(Fiber).to receive(:new).and_yield.and_return(fiber) - expect(EM).to receive(:stop) + expect(EM::Synchrony).to receive(:sleep).and_return { + fc.instance_variable_set('@received_signals', ['INT']) + } - # Syslog.should_receive(:opened?).and_return(true) - # Syslog.should_receive(:close) + expect(Syslog).to receive(:opened?).and_return(true) + expect(Syslog).to receive(:close) fc.start(:signals => false) - fc.stop end it "handles an exception raised by a pikelet and shuts down" do expect(Flapjack::Logger).to receive(:new).and_return(logger) expect(logger).to receive(:fatal) @@ -61,23 +60,19 @@ expect(Time).to receive(:now).and_return(time) fc = Flapjack::Coordinator.new(config) expect(Flapjack::Pikelet).to receive(:create).with('processor', - :config => cfg['processor'], :redis_config => {}, :boot_time => time, :coordinator => fc) + :config => cfg['processor'], :redis_config => {}, :boot_time => time) .and_return(processor) - expect(fiber).to receive(:resume) - expect(Fiber).to receive(:new).and_yield.and_return(fiber) - expect(EM).to receive(:stop) - # Syslog.should_receive(:opened?).and_return(true) - # Syslog.should_receive(:close) + expect(Syslog).to receive(:opened?).and_return(true) + expect(Syslog).to receive(:close) fc.start(:signals => false) - fc.stop end it "loads an old executive pikelet config block with no new data" do cfg = {'executive' => {'enabled' => true}} expect(EM).to receive(:synchrony).and_yield @@ -98,26 +93,25 @@ expect(Time).to receive(:now).and_return(time) fc = Flapjack::Coordinator.new(config) expect(Flapjack::Pikelet).to receive(:create).with('processor', - :config => cfg['executive'], :redis_config => {}, :boot_time => time, :coordinator => fc). + :config => cfg['executive'], :redis_config => {}, :boot_time => time). and_return(processor) expect(Flapjack::Pikelet).to receive(:create).with('notifier', - :config => cfg['executive'], :redis_config => {}, :boot_time => time, :coordinator => fc). + :config => cfg['executive'], :redis_config => {}, :boot_time => time). and_return(notifier) - expect(fiber).to receive(:resume) - expect(Fiber).to receive(:new).and_yield.and_return(fiber) - expect(EM).to receive(:stop) + expect(EM::Synchrony).to receive(:sleep).and_return { + fc.instance_variable_set('@received_signals', ['INT']) + } - # Syslog.should_receive(:opened?).and_return(true) - # Syslog.should_receive(:close) + expect(Syslog).to receive(:opened?).and_return(true) + expect(Syslog).to receive(:close) fc.start(:signals => false) - fc.stop end it "loads an old executive pikelet config block with some new data" do cfg = {'executive' => {'enabled' => true}, 'processor' => {'foo' => 'bar'}, @@ -136,23 +130,22 @@ expect(Time).to receive(:now).and_return(time) fc = Flapjack::Coordinator.new(config) expect(Flapjack::Pikelet).to receive(:create).with('processor', :config => cfg['executive'].merge(cfg['processor']), - :redis_config => {}, :boot_time => time, :coordinator => fc). + :redis_config => {}, :boot_time => time). and_return(processor) - expect(fiber).to receive(:resume) - expect(Fiber).to receive(:new).and_yield.and_return(fiber) - expect(EM).to receive(:stop) + expect(EM::Synchrony).to receive(:sleep).and_return { + fc.instance_variable_set('@received_signals', ['INT']) + } - # Syslog.should_receive(:opened?).and_return(true) - # Syslog.should_receive(:close) + expect(Syslog).to receive(:opened?).and_return(true) + expect(Syslog).to receive(:close) fc.start(:signals => false) - fc.stop end it "traps system signals and shuts down" do expect(Flapjack::Logger).to receive(:new).and_return(logger) @@ -164,14 +157,13 @@ expect(Kernel).to receive(:trap).with('HUP').and_yield expect(config).to receive(:all).and_return({}) expect(config).to receive(:for_redis).and_return({}) fc = Flapjack::Coordinator.new(config) - expect(fc).to receive(:stop).exactly(3).times - expect(fc).to receive(:reload) fc.send(:setup_signals) + expect(fc.instance_variable_get('@received_signals')).to eq(['INT', 'TERM', 'QUIT', 'HUP']) end it "only traps two system signals on Windows" do expect(Flapjack::Logger).to receive(:new).and_return(logger) @@ -183,13 +175,13 @@ expect(Kernel).not_to receive(:trap).with('HUP') expect(config).to receive(:all).and_return({}) expect(config).to receive(:for_redis).and_return({}) fc = Flapjack::Coordinator.new(config) - expect(fc).to receive(:stop).twice fc.send(:setup_signals) + expect(fc.instance_variable_get('@received_signals')).to eq(['INT', 'TERM']) end it "stops one pikelet and starts another on reload" do expect(Flapjack::Logger).to receive(:new).and_return(logger) @@ -216,23 +208,18 @@ fc = Flapjack::Coordinator.new(config) jabber = double('jabber') expect(Flapjack::Pikelet).to receive(:create). with('jabber', :config => {"enabled" => true}, :redis_config => {}, - :boot_time => time, :coordinator => fc). + :boot_time => time). and_return(jabber) expect(jabber).to receive(:start) - expect(fiber).to receive(:resume) - expect(Fiber).to receive(:new).and_yield.and_return(fiber) - fc.instance_variable_set('@boot_time', time) fc.instance_variable_set('@pikelets', [processor]) - fc.reload + fc.send(:reload) expect(fc.instance_variable_get('@pikelets')).to eq([jabber]) - - end it "reloads a pikelet config without restarting it" do expect(Flapjack::Logger).to receive(:new).and_return(logger) @@ -257,11 +244,11 @@ expect(config).to receive(:for_redis).and_return({}) fc = Flapjack::Coordinator.new(config) fc.instance_variable_set('@boot_time', time) fc.instance_variable_set('@pikelets', [processor]) - fc.reload + fc.send(:reload) expect(fc.instance_variable_get('@pikelets')).to eq([processor]) end it "reloads a pikelet config while restarting it" do expect(Flapjack::Logger).to receive(:new).and_return(logger) @@ -284,26 +271,23 @@ expect(processor).to receive(:reload).with(new_cfg['processor']).and_return(false) expect(processor).to receive(:stop) expect(processor).to receive(:update_status) expect(processor).to receive(:status).exactly(3).times.and_return('stopped') - expect(fiber).to receive(:resume) - expect(Fiber).to receive(:new).and_yield.and_return(fiber) - new_exec = double('new_executive') expect(new_exec).to receive(:start) expect(config).to receive(:for_redis).and_return({}) fc = Flapjack::Coordinator.new(config) expect(Flapjack::Pikelet).to receive(:create). with('processor', :config => new_cfg['processor'], :redis_config => {}, - :boot_time => time, :coordinator => fc). + :boot_time => time). and_return(new_exec) fc.instance_variable_set('@boot_time', time) fc.instance_variable_set('@pikelets', [processor]) - fc.reload + fc.send(:reload) expect(fc.instance_variable_get('@pikelets')).to eq([new_exec]) end end