Skip to content

Commit

Permalink
Fix running the last attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
Riddlerrr committed Oct 7, 2024
1 parent 397cb81 commit 65a8048
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def delivered?

def still_attempting?
return false if delivered?
attempt_count < max_attempts
attempt_count <= max_attempts
end

def failed?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "test_helper"

class Webhooks::Outgoing::DeliveryTest < ActiveSupport::TestCase
include ActiveJob::TestHelper

setup do
@team = Team.create!(name: "test-team")
@endpoint = Webhooks::Outgoing::Endpoint.create!(url: "https://example.com/webhook", name: "test", team: @team)
@subject = @team
@event = Webhooks::Outgoing::Event.create!(team: @team, subject: @subject, api_version: "1")
end

test "#deliver_async schedule jobs" do
delivery = Webhooks::Outgoing::Delivery.create!(endpoint: @endpoint, event: @event)
freeze_time

# first job runs immediately
assert_enqueued_with(job: Webhooks::Outgoing::DeliveryJob, at: nil) do
delivery.deliver_async
end

# shedule other jobs with the delays from ATTEMPT_SCHEDULE
Webhooks::Outgoing::Delivery::ATTEMPT_SCHEDULE.each do |attempt, delay|
delivery.reload
delivery.delivery_attempts.create!(attempt_number: attempt, response_code: 500, error_message: "error")
assert_enqueued_with(job: Webhooks::Outgoing::DeliveryJob, at: delay.from_now) do
delivery.deliver_async
end
end

assert_equal Webhooks::Outgoing::Delivery::ATTEMPT_SCHEDULE.size, Webhooks::Outgoing::DeliveryAttempt.count, "amount of attempts should e equal to ATTEMPT_SCHEDULE"
end
end

0 comments on commit 65a8048

Please sign in to comment.