Sha256: 1ce6e6c225537d5091d158328095b78022738d76eb26f73b70404e3b401bb01e

Contents?: true

Size: 1.98 KB

Versions: 12

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

describe BigBrother::Ticker do
  describe ".schedule!" do
    it "schedules the ticker to run ten times every second" do
      EventMachine.should_receive(:add_periodic_timer).with(0.1)

      BigBrother::Ticker.schedule!
    end
  end

  describe ".tick" do
    describe "end-to-end" do
      run_in_reactor
      with_litmus_server '127.0.0.1', 8081, 74
      with_litmus_server public_ip_address, 8082, 76

      it "monitors clusters requiring monitoring" do
        BigBrother.clusters['test'] = Factory.cluster(
          :fwmark => 100,
          :nodes => [
            Factory.node(:address  => '127.0.0.1', :port => 8081),
            Factory.node(:address  => public_ip_address, :port => 8082)
          ]
        )
        BigBrother.clusters['test'].start_monitoring!
        @stub_executor.commands.clear

        BigBrother::Ticker.tick

        @stub_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 74")
        @stub_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server #{public_ip_address} --ipip --weight 76")
      end

      it "only monitors a cluster once in the given interval" do
        BigBrother.clusters['test'] = Factory.cluster(
          :fwmark => 100,
          :nodes => [Factory.node(:address  => '127.0.0.1', :port => 8081)]
        )
        BigBrother.clusters['test'].start_monitoring!
        @stub_executor.commands.clear

        BigBrother::Ticker.tick
        BigBrother::Ticker.tick

        @stub_executor.commands.should == ["ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 74"]
      end
    end

    it "monitors clusters requiring monitoring" do
      BigBrother.clusters['one'] = Factory.cluster
      BigBrother.clusters['two'] = Factory.cluster
      BigBrother.clusters['two'].start_monitoring!

      BigBrother.clusters['two'].should_receive(:monitor_nodes)

      BigBrother::Ticker.tick
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
big_brother-0.6.8 spec/big_brother/ticker_spec.rb
big_brother-0.6.7 spec/big_brother/ticker_spec.rb
big_brother-0.6.6 spec/big_brother/ticker_spec.rb
big_brother-0.6.5 spec/big_brother/ticker_spec.rb
big_brother-0.6.4 spec/big_brother/ticker_spec.rb
big_brother-0.6.3 spec/big_brother/ticker_spec.rb
big_brother-0.6.2 spec/big_brother/ticker_spec.rb
big_brother-0.6.1 spec/big_brother/ticker_spec.rb
big_brother-0.6.0 spec/big_brother/ticker_spec.rb
big_brother-0.5.0 spec/big_brother/ticker_spec.rb
big_brother-0.4.1 spec/big_brother/ticker_spec.rb
big_brother-0.4.0 spec/big_brother/ticker_spec.rb