spec/unit/runner_spec.rb in mcollective-client-2.5.3 vs spec/unit/runner_spec.rb in mcollective-client-2.6.0
- old
+ new
@@ -7,11 +7,11 @@
let(:config) do
c = mock
c.stubs(:loadconfig)
c.stubs(:configured).returns(true)
c.stubs(:mode=)
- c.stubs(:direct_addressing).returns(true)
+ c.stubs(:direct_addressing).returns(false)
c.stubs(:registerinterval).returns(1)
c.stubs(:soft_shutdown).returns(false)
c
end
@@ -48,17 +48,19 @@
describe 'initialize' do
it 'should set up the signal handlers when not on windows' do
Util.stubs(:windows).returns(false)
Signal.expects(:trap).with('USR1')
Signal.expects(:trap).with('USR2')
+ Signal.expects(:trap).with('WINCH')
Runner.new(nil)
end
it 'should not set up the signal handlers when on windows' do
Util.stubs(:windows?).returns(true)
Signal.expects(:trap).with('USR1').never
Signal.expects(:trap).with('USR2').never
+ Signal.expects(:trap).with('WINCH').never
Util.expects(:setup_windows_sleeper)
Runner.new(nil)
end
@@ -83,11 +85,10 @@
end
let(:agent_thread) do
at = mock
at.stubs(:alive?).returns(true)
- at.expects(:join)
at
end
before :each do
Log.stubs(:debug)
@@ -103,23 +104,17 @@
runner.instance_variable_set(:@state, :stopping)
runner.expects(:stop_threads)
runner.main_loop
end
- it 'should not do a soft_shutdown on windows' do
- config.stubs(:soft_shutdown).returns(true)
- Util.stubs(:windows?).returns(true)
- Log.expects(:warn).with("soft_shutdown specified. This feature is not available on Windows. Shutting down normally.")
- runner.instance_variable_set(:@state, :stopping)
- runner.main_loop
- end
-
it 'should do a soft_shutdown' do
config.stubs(:soft_shutdown).returns(true)
Util.stubs(:windows?).returns(false)
runner.instance_variable_set(:@state, :stopping)
runner.instance_variable_set(:@agent_threads, [agent_thread])
+ runner.expects(:soft_shutdown)
+ runner.expects(:stop_threads)
runner.main_loop
end
end
# Because paused is not a terminal state, we raise after testing pause
@@ -204,35 +199,35 @@
end
before :each do
PluginManager.stubs(:[]).with("registration_plugin").returns(registration_agent)
Data.stubs(:load_data_sources)
- Util.expects(:subscribe).twice
- Util.expects(:make_subscriptions).twice
+ Util.stubs(:subscribe_to_direct_addressing_queue)
end
it 'should receive a message and spawn an agent thread' do
runner.expects(:receive).returns(request)
runner.expects(:agentmsg).with(request)
runner.instance_variable_set(:@exit_receiver_thread, true)
runner.send(:receiver_thread)
end
- it 'should load agents before data plugins' do
- load_order = sequence('load_order')
- Agents.expects(:new).in_sequence(load_order)
- Data.expects(:load_data_sources).in_sequence(load_order)
+ it 'should subscribe to the direct addressing queue if direct_addressing is configured' do
runner.expects(:receive).returns(request)
runner.expects(:agentmsg).with(request)
+ config.stubs(:direct_addressing).returns(true)
+ Util.expects(:subscribe_to_direct_addressing_queue)
runner.instance_variable_set(:@exit_receiver_thread, true)
runner.send(:receiver_thread)
end
- it 'should discard controller messages with an error message' do
+ it 'should load agents before data plugins' do
+ load_order = sequence('load_order')
+ Agents.expects(:new).in_sequence(load_order)
+ Data.expects(:load_data_sources).in_sequence(load_order)
runner.expects(:receive).returns(request)
- request.stubs(:agent).returns("mcollective")
- Log.expects(:error).with("Received a control message, possibly via 'mco controller' but this has been deprecated and removed")
+ runner.expects(:agentmsg).with(request)
runner.instance_variable_set(:@exit_receiver_thread, true)
runner.send(:receiver_thread)
end
it 'should warn when a received message has expired' do
@@ -254,9 +249,92 @@
runner.instance_variable_set(:@exit_receiver_thread, true)
Log.expects(:warn)
Log.expects(:info).with("sleeping for suggested 1 seconds")
runner.expects(:sleep).with(1)
runner.send(:receiver_thread)
+ end
+ end
+ end
+
+ context "soft_shutdown" do
+ let(:runner) do
+ Runner.new(nil)
+ end
+
+ before(:each) do
+ config.stubs(:soft_shutdown).returns(true)
+ end
+
+ describe "#soft_shutdown" do
+ it "should not shutdown if the timeout is set and <= 0" do
+ config.stubs(:soft_shutdown_timeout).returns(0)
+ Log.expects(:warn).twice
+ runner.expects(:windows_soft_shutdown).never
+ runner.expects(:posix_soft_shutdown).never
+ runner.send(:soft_shutdown)
+ end
+
+ it "should call the windows soft_shutdown on Windows" do
+ config.stubs(:soft_shutdown_timeout).returns(1)
+ Util.stubs(:windows?).returns(true)
+ runner.expects(:windows_soft_shutdown)
+ runner.expects(:posix_soft_shutdown).never
+ runner.send(:soft_shutdown)
+ end
+
+ it "should call the posix soft_shutdown when not on windows" do
+ config.stubs(:soft_shutdown_timeout).returns(1)
+ Util.stubs(:windows?).returns(false)
+ runner.expects(:windows_soft_shutdown).never
+ runner.expects(:posix_soft_shutdown)
+ runner.send(:soft_shutdown)
+ end
+ end
+
+ describe "#windows_soft_shutdown" do
+ it "should not shutdown if no timeout is set" do
+ runner.expects(:shutdown_with_timeout).never
+ Log.expects(:warn).times(3)
+ runner.send(:windows_soft_shutdown, nil)
+ end
+
+ it "should shutdown in a timeout" do
+ runner.expects(:shutdown_with_timeout)
+ runner.send(:windows_soft_shutdown, 1)
+ end
+ end
+
+ describe "#posix_soft_shutdown" do
+ it "should shutdown without a timeout" do
+ runner.expects(:stop_agent_threads)
+ runner.send(:posix_soft_shutdown, nil)
+ end
+
+ it "should shutdown with a timeout" do
+ runner.expects(:shutdown_with_timeout)
+ runner.send(:posix_soft_shutdown, 1)
+ end
+ end
+
+ describe "#shutdown_with_timeout" do
+ it "should timeout if it can't stop agent threads in time" do
+ Timeout.expects(:timeout).with(1)
+ runner.send(:shutdown_with_timeout, 1)
+ end
+ end
+
+ describe "#stop_agent_threads" do
+ let(:agent_thread) do
+ at = mock
+ at.stubs(:alive?).returns(true)
+ at
+ end
+
+ it "should stop all agent threads" do
+ runner.instance_variable_set(:@agent_threads, [agent_thread])
+ Log.stubs(:debug)
+ agent_thread.expects(:join)
+ runner.send(:stop_agent_threads)
end
end
end
end
end