Sha256: 45c7a5377db9e91d3776d20594b759a7633272c73473e08b8c00de22d83caf28

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

#!/usr/bin/env rspec

require 'spec_helper'

module MCollective
  if Util.windows?
    require 'mcollective/windows_daemon'

    describe WindowsDaemon do
      describe "#daemonize_runner" do
        it "should only run on the windows platform" do
          Util.expects("windows?").returns(false)
          expect { WindowsDaemon.daemonize_runner }.to raise_error("The Windows Daemonizer should only be used on the Windows Platform")
        end

        it "should not support writing pid files" do
          expect { WindowsDaemon.daemonize_runner(true) }.to raise_error("Writing pid files are not supported on the Windows Platform")
        end

        it "should start the mainloop" do
          Util.stubs(:windows?).returns(true)
          WindowsDaemon.expects(:mainloop)
          WindowsDaemon.daemonize_runner
        end
      end

      describe "#service_main" do
        it "should start the runner" do
          runner = mock
          Runner.stubs(:new).returns(runner)
          d = WindowsDaemon.new
          d.stubs(:running?).returns(true,false)
          d.stubs(:state).returns(WindowsDaemon::RUNNING)
          runner.expects(:run)
          d.service_main
        end

        it "should kill any other living threads on exit" do
          d = WindowsDaemon.new
          d.stubs(:running?).returns(false)
          other = mock
          Thread.stubs(:list).returns([Thread.current, other])
          Thread.current.expects(:kill).never
          other.expects(:kill)
          d.service_main
        end
      end

      describe "#service_stop" do
        it "should log, disconnect, stop the runner and exit" do
          runner = mock
          connector = mock
          connector.expects(:disconnect)
          Log.expects(:info)
          PluginManager.stubs(:[]).with("connector_plugin").returns(connector)
          d = WindowsDaemon.new
          d.instance_variable_set(:@runner, runner)
          runner.expects(:stop)
          d.service_stop
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mcollective-client-2.4.1 spec/unit/windows_daemon_spec.rb
mcollective-client-2.4.0 spec/unit/windows_daemon_spec.rb