Skip to content

Commit

Permalink
Bugfix corrupt dlx headers (#574)
Browse files Browse the repository at this point in the history
Updated amq-protocol.cr to v1.1.10 to fix issue. Also added spec.
  • Loading branch information
viktorerlingsson authored Sep 25, 2023
1 parent a4e10da commit 45c2a2f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ shards:

amq-protocol:
git: https://github.com/cloudamqp/amq-protocol.cr.git
version: 1.1.9
version: 1.1.10

amqp-client:
git: https://github.com/cloudamqp/amqp-client.cr.git
Expand Down
32 changes: 32 additions & 0 deletions spec/dlx_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "./spec_helper"
require "./../src/lavinmq/queue"

describe "Dead lettering" do
q_name = "ttl"
q_name_delayed = "ttl_delayed"
q_name_delayed_2 = "ttl_delayed_2"

# Verifies bugfix for Sub-table memory corruption in amq-protocol.cr
# https://github.com/cloudamqp/amq-protocol.cr/pull/14
it "should be able to read messages that has been dead lettered multiple times" do
with_channel do |ch|
q_delayed_2 = ch.queue(q_name_delayed_2, args: AMQP::Client::Arguments.new(
{"x-message-ttl" => 1, "x-dead-letter-exchange" => "", "x-dead-letter-routing-key" => q_name_delayed}
))
q_delayed = ch.queue(q_name_delayed, args: AMQP::Client::Arguments.new(
{"x-message-ttl" => 1, "x-dead-letter-exchange" => "", "x-dead-letter-routing-key" => q_name}
))
q = ch.queue(q_name)

x = ch.default_exchange
x.publish_confirm("ttl", q_delayed_2.name)
msg = wait_for { q.get }

x_death = msg.properties.headers.not_nil!["x-death"].as(Array(AMQ::Protocol::Field))
x_death.inspect.should be_a(String) # checks that message and headers can be read
x_death.size.should eq 2
x_death[0].as(AMQ::Protocol::Table)["queue"].should eq q_delayed.name
x_death[1].as(AMQ::Protocol::Table)["queue"].should eq q_delayed_2.name
end
end
end

0 comments on commit 45c2a2f

Please sign in to comment.