Skip to content

Commit

Permalink
[taoensso#244] MQ: Add initial-backoff option to enqueue
Browse files Browse the repository at this point in the history
  • Loading branch information
st3fan committed Nov 23, 2020
1 parent f232c2d commit 52a0dca
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions test/taoensso/carmine/tests/message_queue.clj
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,30 @@
(and
(= messages {"mid1" :msg1 "mid2" :msg2})
(= mid-circle ["mid2" "mid1" "end-of-circle"]))))
;; Dupes before the backoff expired
(is (= {:carmine.mq/error :queued-with-backoff} (wcar* (mq/enqueue tq :msg1 :mid1))))
(is (= {:carmine.mq/error :queued-with-backoff} (wcar* (mq/enqueue tq :msg2 :mid2))))
;; Both should be queued with backoff before the backoff expires
(is (= :queued-with-backoff (wcar* (mq/message-status tq :mid1))))
(is (= :queued-with-backoff (wcar* (mq/message-status tq :mid2))))
;;
;; Move time past second message
(is (do (Thread/sleep 125) true))
(is (= :queued-with-backoff (wcar* (mq/message-status tq :mid1))))
(is (= :queued (wcar* (mq/message-status tq :mid2))))
;;
;; Move time past first message
(is (do (Thread/sleep 1500) true))
(is (= :queued (wcar* (mq/message-status tq :mid1))))
(is (= :queued (wcar* (mq/message-status tq :mid2))))

;; Dupe
;; (is (= {:carmine.mq/error :queued-with-backoff} (wcar* (mq/enqueue tq :msg1 :mid1))))

;; (is (= "eoq-backoff" (wcar* (dequeue* tq))))
;; (is (= ["mid1" :msg1 1] (wcar* (dequeue* tq)))) ; New msg
;; (is (= :locked (wcar* (mq/message-status tq :mid1))))
;; (is (= "eoq-backoff" (wcar* (dequeue* tq))))
;; (is (= nil (wcar* (dequeue* tq)))) ; Locked msg
;; Dupes after the backoff expired
(is (= {:carmine.mq/error :queued} (wcar* (mq/enqueue tq :msg1 :mid1))))
(is (= {:carmine.mq/error :queued} (wcar* (mq/enqueue tq :msg2 :mid2))))
;; TODO Is the order of retrieval actually predictable?
(is (= "eoq-backoff" (wcar* (dequeue* tq))))
(is (= ["mid1" :msg1 1] (wcar* (dequeue* tq))))
(is (= :locked (wcar* (mq/message-status tq :mid1))))
(is (= ["mid2" :msg2 1] (wcar* (dequeue* tq))))
(is (= :locked (wcar* (mq/message-status tq :mid2))))
(is (= "eoq-backoff" (wcar* (dequeue* tq))))
(is (= nil (wcar* (dequeue* tq))))
)

0 comments on commit 52a0dca

Please sign in to comment.