Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback value is not used #65

Open
filipesilva opened this issue Oct 3, 2023 · 0 comments
Open

Fallback value is not used #65

filipesilva opened this issue Oct 3, 2023 · 0 comments

Comments

@filipesilva
Copy link

I think the value returned from the :fallback on with-retry is not used. I can reproduce this by modifying the fallback test.

(deftest fallback
  ;; This is the original test
  (testing "fallback value is same as original value"
    (is (= 10 (dh/with-retry {:fallback (fn [v e]
                                          (is (= v 10))
                                          (is (nil? e))
                                          v)
                              :retry-if (fn [v e] (< v 10))}
                dh/*executions*)))

    ;; Here I changed fallback to instead return :fail.
    (testing "fallback value is different from original value"
      (is (= :fail (dh/with-retry {:fallback (fn [v e]
                                               (is (= v 10))
                                               (is (nil? e))
                                               :fail)
                                   :retry-if (fn [v e] (< v 10))}
                     dh/*executions*))))))
1 non-passing tests:

Fail in fallback
fallback value is same as original value fallback value is different from original value

expected: :fail

  actual: 10          
    diff: - :fail          
          + 10    

Here's a simpler test that also fails:

(deftest simple-fallback
  (is (= :fallback (dh/with-retry {:retry-when false
                                   :max-retries 3
                                   :fallback :fallback}
                     false))))
1 non-passing tests:

Fail in simple-fallback

expected: :fallback

  actual: false          
    diff: - :fallback          
          + false    

I'm not sure :fallback is even running though:

(dh/with-retry {:retry-when  false
                :max-retries 3
                :on-success  (fn [_ _] (println "success"))
                :on-failure  (fn [_ _] (println "failure"))
                :on-retry    (fn [_ _] (println "retry"))
                :fallback    (fn [_ _] (println "fallback") :fallback)}
  false)

;; retry
;; retry
;; retry
;; failure
;; => false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant