rSpec テストで AMQP への接続に問題があります。次のようなコードがあります。
Module Rabbit
Class Client
def start
EventMachine.run do
connection = AMQP.connect(Settings_object) #it holds host, username and password information
channel = AMQP::Channel.new(connection)
channel.queue("queue_name", :durable => true)
channel.default_exchange.publish("A test message", :routing_key => "queue_name")
end
end
end
Module Esper
Class Server
def start
EventMachine.run do
connection = AMQP.connect(Settings_object) #it holds host, username and password information
=begin
Some code to subscribe to queues
=end
end
end
end
私の問題は、rspec を実行するときです。
@client = Rabbit::Client.new
@server = Esper::Server.new
Thread.new do
@client.start
end
Thread.new do
@server.start
end
最初、クライアントは AMQP に接続でき、サーバーは接続できませんが、2 回目に実行すると、クライアントはサーバーに接続できません。この問題を克服する方法がわかりません。2 回目に実行したときにクライアントが接続を停止する理由がわかりません。