From 232fd6b8184ea1de353ae7b11c9cbafb26a529da Mon Sep 17 00:00:00 2001 From: Magnus Landerblom Date: Tue, 12 Dec 2023 12:20:58 +0100 Subject: [PATCH] Spec: Add a spec to verify that DLX message count is updated (#601) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add a spec to verify that DLX message count is updated * Use two queues two get two x-deaths This reverts commit 7f8e3ad649ede3f6cc30e07d535456ece6ac9656 and the original bugfix that was instead fixed in amq-protocol.cr . --------- Co-authored-by: Jon Börjesson Co-authored-by: Christina --- spec/dlx_spec.cr | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/spec/dlx_spec.cr b/spec/dlx_spec.cr index 6589876cd3..bbb4a276d6 100644 --- a/spec/dlx_spec.cr +++ b/spec/dlx_spec.cr @@ -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