Sha256: 343211716ef9acebb9e5f8c3dc8da098c46293f9d2140f411bc6ff1a6773fda9

Contents?: true

Size: 1.66 KB

Versions: 26

Compression:

Stored size: 1.66 KB

Contents

require 'gorgon/ping_service'

describe "PingService" do
  describe "#ping_listeners" do
    let(:configuration){ {:connection => {:host => "host"}, :originator_log_file => "file.log"}}
    let(:protocol) { stub("OriginatorProtocol", :connect => nil, :ping => nil,
                          :receive_payloads => nil, :disconnect => nil,
                          :send_message_to_listeners => nil)}
    let(:logger){ stub("Originator Logger", :log => nil, :log_message => nil)}

    before do
      $stdout.stub!(:write)
      PingService.any_instance.stub(:load_configuration_from_file).and_return configuration
      EventMachine.stub!(:run).and_yield
      EM.stub!(:add_timer).and_yield
      OriginatorLogger.stub!(:new).and_return logger
    end

    it "connnects and calls OriginatorProtocol#send_message_to_listeners" do
      OriginatorProtocol.should_receive(:new).once.ordered.and_return(protocol)
      protocol.should_receive(:connect).once.ordered.with({:host => "host"}, anything)
      protocol.should_receive(:send_message_to_listeners).once.ordered
      PingService.new.ping_listeners
    end

    context "after sending ping messages" do
      before do
        OriginatorProtocol.stub!(:new).and_return(protocol)
        @service = PingService.new
      end

      it "adds an Event machine timer" do
        EM.should_receive(:add_timer).and_yield
        @service.ping_listeners
      end

      it "receives a ping_response message" do
        payload = {:type => "ping_response", :hostname => "host", :version => "1.1.1"}
        protocol.should_receive(:receive_payloads).and_yield Yajl::Encoder.encode(payload)
        @service.ping_listeners
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
gorgon-0.4.0 spec/ping_service_spec.rb
gorgon-0.4.0.rc2 spec/ping_service_spec.rb
gorgon-0.4.0.rc1 spec/ping_service_spec.rb
gorgon-0.3.2 spec/ping_service_spec.rb
gorgon-0.3.1 spec/ping_service_spec.rb
gorgon-0.3.0 spec/ping_service_spec.rb