1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
require "spec_helper"
describe Bunny::Channel do
let(:connection) do
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
c.start
c
end
after :each do
connection.close
end
context "when closed" do
it "releases the id" do
ch = connection.create_channel
n = ch.number
expect(ch).to be_open
ch.close
expect(ch).to be_closed
# a new channel with the same id can be created
connection.create_channel(n)
end
end
context "when double closed" do
# bunny#528
it "raises a meaningful exception" do
ch = connection.create_channel
expect(ch).to be_open
ch.close
expect(ch).to be_closed
expect { ch.close }.to raise_error(Bunny::ChannelAlreadyClosed)
end
end
context "when double closed after a channel-level protocol exception" do
# bunny#528
it "raises a meaningful exception" do
ch = connection.create_channel
s = "bunny-temp-q-#{rand}"
expect(ch).to be_open
ch.queue_declare(s, durable: false)
expect do
ch.queue_declare(s, durable: true)
end.to raise_error(Bunny::PreconditionFailed)
# channel.close is sent and handled concurrently with the test
sleep 1
expect(ch).to be_closed
expect { ch.close }.to raise_error(Bunny::ChannelAlreadyClosed)
cleanup_ch = connection.create_channel
cleanup_ch.queue_delete(s)
cleanup_ch.close
end
end
end
|