Skip to content

Commit

Permalink
Added spec for new x-death count header
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronkk committed Apr 20, 2015
1 parent 521152e commit 11cdcbc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sneakers/handlers/maxretry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def failure_count(headers)
if x_death_array.count != 1
x_death_array.count
else
x_death_array.first['count']
x_death_array.first['count'] || 1
end
end
end
Expand Down
40 changes: 40 additions & 0 deletions spec/sneakers/worker_handlers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ def process(*args,&block)

describe 'Maxretry' do
let(:max_retries) { nil }
let(:props_with_x_death_count) {
{
:headers => {
"x-death" => [
{
"count" => 3,
"reason" => "expired",
"queue" => "downloads-retry",
"time" => Time.now,
"exchange" => "RawMail-retry",
"routing-keys" => ["RawMail"]
},
{
"count" => 3,
"reason" => "rejected",
"queue" => "downloads",
"time" => Time.now,
"exchange" => "",
"routing-keys" => ["RawMail"]
}
]
},
:delivery_mode => 1
}
}

before(:each) do
@opts = {
Expand Down Expand Up @@ -228,6 +253,21 @@ def publish(data, opts)
Time.parse(data['failed_at']).wont_be_nil
end

it 'counts the number of attempts using the count key' do
mock(@header).routing_key { '#' }
mock(channel).acknowledge(37, false)

@error_exchange.extend MockPublish
worker.do_work(@header, props_with_x_death_count, :reject, @handler)
@error_exchange.called.must_equal(true)
@error_exchange.opts.must_equal({ :routing_key => '#' })
data = JSON.parse(@error_exchange.data)
data['error'].must_equal('reject')
data['num_attempts'].must_equal(4)
data['payload'].must_equal(Base64.encode64(:reject.to_s))
Time.parse(data['failed_at']).wont_be_nil
end

end
end

Expand Down

0 comments on commit 11cdcbc

Please sign in to comment.