mirror of
https://github.com/jimeh/amqp-failover.git
synced 2026-02-19 02:46:43 +00:00
added specs for AMQP::Failover::Fallback
This commit is contained in:
31
spec/unit/amqp/failover/fallback_helper.rb
Normal file
31
spec/unit/amqp/failover/fallback_helper.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
class FallbackHelper < AMQP::Failover::Fallback
|
||||
|
||||
class << self
|
||||
alias :real_start_monitoring :start_monitoring
|
||||
def start_monitoring(*args, &block)
|
||||
$called << :start_monitoring
|
||||
real_start_monitoring(*args, &block)
|
||||
end
|
||||
end
|
||||
|
||||
alias :real_initialize :initialize
|
||||
def initialize(*args)
|
||||
$called << :initialize
|
||||
EM.start_server('127.0.0.1', 9999) if $start_count == 2
|
||||
$start_count += 1
|
||||
real_initialize(*args)
|
||||
end
|
||||
|
||||
alias :real_connection_completed :connection_completed
|
||||
def connection_completed
|
||||
$called << :connection_completed
|
||||
real_connection_completed
|
||||
end
|
||||
|
||||
alias :real_close_connection :close_connection
|
||||
def close_connection
|
||||
$called << :close_connection
|
||||
real_close_connection
|
||||
end
|
||||
|
||||
end
|
||||
51
spec/unit/amqp/failover/fallback_spec.rb
Normal file
51
spec/unit/amqp/failover/fallback_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
# encoding: utf-8
|
||||
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
|
||||
|
||||
require 'spec_helper'
|
||||
require 'fallback_helper'
|
||||
|
||||
describe AMQP::Failover::Fallback do
|
||||
|
||||
before(:each) do
|
||||
$called = []
|
||||
$start_count = 0
|
||||
@args = { :host => 'localhost', :port => 9999, :retry_interval => 0.01 }
|
||||
end
|
||||
|
||||
it "should initialize" do
|
||||
EM.run {
|
||||
EM.start_server('127.0.0.1', 9999)
|
||||
@mon = FallbackHelper.monitor(@args) do
|
||||
$called << :done_block
|
||||
EM.stop_event_loop
|
||||
end
|
||||
}
|
||||
$start_count.should == 1
|
||||
$called.should have(5).items
|
||||
$called.uniq.should have(5).items
|
||||
$called.should include(:start_monitoring)
|
||||
$called.should include(:initialize)
|
||||
$called.should include(:connection_completed)
|
||||
$called.should include(:close_connection)
|
||||
$called.should include(:done_block)
|
||||
end
|
||||
|
||||
it "should retry on error" do
|
||||
EM.run {
|
||||
@mon = FallbackHelper.monitor(@args) do
|
||||
$called << :done_block
|
||||
EM.stop_event_loop
|
||||
end
|
||||
}
|
||||
$start_count.should >= 3
|
||||
$called.should have($start_count + 4).items
|
||||
$called.uniq.should have(5).items
|
||||
$called.should include(:start_monitoring)
|
||||
$called.should include(:initialize)
|
||||
$called.should include(:connection_completed)
|
||||
$called.should include(:close_connection)
|
||||
$called.should include(:done_block)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user