Skip to content

Commit

Permalink
Spec: Add a spec to verify that DLX message count is updated (#601)
Browse files Browse the repository at this point in the history
* Add a spec to verify that DLX message count is updated

* Use two queues two get two x-deaths

This reverts commit 7f8e3ad and the original bugfix that was instead fixed in amq-protocol.cr .


---------

Co-authored-by: Jon Börjesson <[email protected]>
Co-authored-by: Christina <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 07535ad commit 232fd6b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions spec/dlx_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,47 @@ describe "Dead lettering" do

msg.timestamp.should be > ts
end

it "should update count in x-death" do
with_channel do |ch|
q_name = "q_dlx"
q = ch.queue(q_name, args: AMQP::Client::Arguments.new(
{"x-dead-letter-exchange" => "", "x-dead-letter-routing-key" => "#{q_name}2"}
))
_q2 = ch.queue("#{q_name}2", args: AMQP::Client::Arguments.new(
{"x-dead-letter-exchange" => "", "x-dead-letter-routing-key" => q_name, "x-message-ttl" => 1}
))

done = Channel(AMQP::Client::DeliverMessage).new
i = 0
q.subscribe(no_ack: false) do |env|
env.reject
if i == 10
env.ack
done.send env
end
i += 1
end
ch.default_exchange.publish_confirm("msg", q.name)

msg = done.receive
headers = msg.properties.headers.should_not be_nil
x_death = headers["x-death"].as?(Array(AMQ::Protocol::Field)).should_not be_nil
x_death_q_dlx_rejected = x_death.find do |xd|
xd = xd.as(AMQ::Protocol::Table)
xd["queue"] == q_name &&
xd["reason"] == "rejected"
end
x_death_q_dlx_rejected = x_death_q_dlx_rejected.as?(AMQ::Protocol::Table).should_not be_nil
x_death_q_dlx_rejected["count"].should eq 10

x_death_q_dlx2_expired = x_death.find do |xd|
xd = xd.as(AMQ::Protocol::Table)
xd["queue"] == "#{q_name}2" &&
xd["reason"] == "expired"
end
x_death_q_dlx2_expired = x_death_q_dlx2_expired.as?(AMQ::Protocol::Table).should_not be_nil
x_death_q_dlx2_expired["count"].should eq 10
end
end
end

0 comments on commit 232fd6b

Please sign in to comment.