Skip to content

Commit

Permalink
[Anmol] Exponential Backoff calculation bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol Vijaywargiya committed Nov 2, 2020
1 parent 6e75c19 commit 1e2e2e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ziggurat/messaging/producer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
_NOTE: Exponential backoff for channel retries is an experimental feature. It should not be used until released in a stable version._"
[retry-count message-retry-count queue-timeout-ms]
(let [exponential-backoff (get-backoff-exponent retry-count message-retry-count)]
(int (* (dec (Math/pow 2 exponential-backoff)) queue-timeout-ms))))
(long (* (dec (Math/pow 2 exponential-backoff)) queue-timeout-ms))))

(defn get-queue-timeout-ms [message-payload]
"Calculate queue timeout for delay queue. Uses the value from [[get-exponential-backoff-timeout-ms]] if exponential backoff enabled."
Expand Down
14 changes: 13 additions & 1 deletion test/ziggurat/messaging/producer_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -612,4 +612,16 @@
:count 50
:type :exponential}))]
;; For 25 max exponential retries, exponent comes to 25-20=5, which makes timeout = 100*(2^5-1) = 3100
(is (= 3100 (producer/get-queue-timeout-ms message)))))))
(is (= 3100 (producer/get-queue-timeout-ms message))))))
(testing "when exponential retries are enabled with total retries as 25 and if the message has already been retried 24 times, then the queue-timeout is calculated without any failure"
(let [message (assoc message-payload :retry-count 1)]
(with-redefs [config/ziggurat-config (constantly (assoc (config/ziggurat-config)
:retry {:enabled true
:count 25
:type :exponential}
:rabbit-mq {:delay {:queue-timeout-ms 5000}}))]
;; For 25 max exponential retries, exponent comes to 25-1=24, which makes timeout = 5000*(2^24-1) = 83886075000
(is (= 83886075000 (producer/get-queue-timeout-ms message)))))))



0 comments on commit 1e2e2e8

Please sign in to comment.