mirror of
https://github.com/jimeh/amqp-failover.git
synced 2026-02-19 10:56:44 +00:00
major restructuring, specs probably all break
right now
This commit is contained in:
@@ -5,7 +5,7 @@ require 'spec_helper'
|
||||
require 'amqp/server'
|
||||
require 'server_helper'
|
||||
|
||||
describe "Simple AMQP connection with FailoverClient" do
|
||||
describe "Simple AMQP connection with FailoverClient loaded" do
|
||||
|
||||
before(:all) do
|
||||
@log = ServerHelper.log
|
||||
@@ -28,4 +28,21 @@ describe "Simple AMQP connection with FailoverClient" do
|
||||
}
|
||||
end
|
||||
|
||||
it "should connect and get disconnected" do
|
||||
lambda {
|
||||
EM.run {
|
||||
spid = start_server
|
||||
conn = AMQP.connect(:host => 'localhost', :port => 15672)
|
||||
EM.add_timer(0.1) {
|
||||
conn.should be_connected
|
||||
stop_server(spid)
|
||||
EM.add_timer(0.1) {
|
||||
conn.should_not be_connected
|
||||
EM.stop
|
||||
}
|
||||
}
|
||||
}
|
||||
}.should raise_error(AMQP::Error, "Could not connect to server localhost:15672")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -16,3 +16,21 @@ module ServerHelper
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
# Helper methods
|
||||
#
|
||||
|
||||
def start_server(port = 15762, timeout = 2)
|
||||
bef_fork = EM.forks.clone
|
||||
EM.fork {
|
||||
EM.start_server('localhost', port, ServerHelper)
|
||||
EM.add_timer(timeout) { EM.stop }
|
||||
}
|
||||
(EM.forks - bef_fork).first
|
||||
end
|
||||
|
||||
def stop_server(pid)
|
||||
Process.kill('TERM', pid)
|
||||
end
|
||||
@@ -16,3 +16,34 @@ require 'amqp/failover'
|
||||
|
||||
require 'rspec'
|
||||
require 'rspec/autorun'
|
||||
|
||||
|
||||
#
|
||||
# Helper methods
|
||||
#
|
||||
|
||||
def wait_while(timeout = 10, retry_interval = 0.1, &block)
|
||||
start = Time.now
|
||||
while block.call
|
||||
break if (Time.now - start).to_i >= timeout
|
||||
sleep(retry_interval)
|
||||
end
|
||||
end
|
||||
|
||||
# stolen from Pid::running? from daemons gem
|
||||
def pid_running?(pid)
|
||||
return false unless pid
|
||||
|
||||
# Check if process is in existence
|
||||
# The simplest way to do this is to send signal '0'
|
||||
# (which is a single system call) that doesn't actually
|
||||
# send a signal
|
||||
begin
|
||||
Process.kill(0, pid)
|
||||
return true
|
||||
rescue Errno::ESRCH
|
||||
return false
|
||||
rescue ::Exception # for example on EPERM (process exists but does not belong to us)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,13 +3,17 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe AMQP::Failover::Config do
|
||||
describe 'AMQP::Failover::Config' do
|
||||
|
||||
before(:all) do
|
||||
# @conf = AMQP::Failover::Config.new
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
@conf = AMQP::Failover::Config.new
|
||||
[:primary, :configs, :refs].each do |var|
|
||||
@conf.instance_variable_set("@#{var}", nil)
|
||||
end
|
||||
# [:primary, :configs, :refs].each do |var|
|
||||
# @conf.instance_variable_set("@#{var}", nil)
|
||||
# end
|
||||
@raw_configs = [
|
||||
{:host => 'rabbit3.local'},
|
||||
{:host => 'rabbit2.local'},
|
||||
@@ -19,9 +23,9 @@ describe AMQP::Failover::Config do
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
[:primary, :configs, :refs].each do |var|
|
||||
@conf.instance_variable_set("@#{var}", nil)
|
||||
end
|
||||
# [:primary, :configs, :refs].each do |var|
|
||||
# @conf.instance_variable_set("@#{var}", nil)
|
||||
# end
|
||||
end
|
||||
|
||||
it "should set and get configs" do
|
||||
@@ -31,21 +35,24 @@ describe AMQP::Failover::Config do
|
||||
@conf.set(@raw_configs[0])
|
||||
@conf.configs.should have(1).items
|
||||
@conf.get(0).should == @configs[0]
|
||||
@conf[0].should == @configs[0]
|
||||
|
||||
@conf.set(@raw_configs[1])
|
||||
@conf.configs.should have(2).items
|
||||
@conf.get(1).should == @configs[1]
|
||||
@conf[1].should == @configs[1]
|
||||
|
||||
@conf.set(@raw_configs[1], :the_one)
|
||||
@conf.configs.should have(2).items
|
||||
@conf.get(1).should == @configs[1]
|
||||
@conf.get(:the_one).should == @configs[1]
|
||||
@conf[:the_one].should == @configs[1]
|
||||
|
||||
@conf.load_array(@raw_configs)
|
||||
@conf.configs.should have(3).items
|
||||
@conf.get_primary.should == @configs[0]
|
||||
@conf.primary = 1
|
||||
@conf.get_primary.should == @configs[1]
|
||||
@conf[:primary].should == @configs[1]
|
||||
end
|
||||
|
||||
it "should #find_next" do
|
||||
|
||||
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
|
||||
require 'spec_helper'
|
||||
require 'server_discovery_helper'
|
||||
|
||||
describe AMQP::Failover::ServerDiscovery do
|
||||
describe 'AMQP::Failover::ServerDiscovery' do
|
||||
|
||||
before(:each) do
|
||||
$called = []
|
||||
|
||||
Reference in New Issue
Block a user