|
| 1 | +;; Copyright © Manetu, Inc. All rights reserved |
| 2 | + |
| 3 | +(ns temporal.test.local-retry |
| 4 | + (:require [clojure.test :refer :all] |
| 5 | + [promesa.core :as p] |
| 6 | + [taoensso.timbre :as log] |
| 7 | + [temporal.client.core :as c] |
| 8 | + [temporal.workflow :refer [defworkflow]] |
| 9 | + [temporal.activity :refer [defactivity] :as a] |
| 10 | + [temporal.test.utils :as t]) |
| 11 | + (:import (io.temporal.client WorkflowFailedException) |
| 12 | + [io.temporal.failure TimeoutFailure ActivityFailure] |
| 13 | + [java.time Duration])) |
| 14 | + |
| 15 | +(use-fixtures :once t/wrap-service) |
| 16 | + |
| 17 | +(defactivity local-retry-activity |
| 18 | + [ctx args] |
| 19 | + (log/info "local-retry-activity") |
| 20 | + (Thread/sleep 100000000)) |
| 21 | + |
| 22 | +(defworkflow local-retry-workflow |
| 23 | + [args] |
| 24 | + (log/info "local-retry-workflow:" args) |
| 25 | + @(-> (a/local-invoke local-retry-activity {} (merge args {:do-not-include-args true |
| 26 | + :start-to-close-timeout (Duration/ofMillis 500)})) |
| 27 | + (p/catch ActivityFailure |
| 28 | + :fail))) |
| 29 | + |
| 30 | +(defn exec [args] |
| 31 | + (let [workflow (t/create-workflow local-retry-workflow)] |
| 32 | + (c/start workflow args) |
| 33 | + @(-> (c/get-result workflow) |
| 34 | + (p/then (constantly :fail)) |
| 35 | + (p/catch WorkflowFailedException |
| 36 | + (fn [ex] |
| 37 | + (if (instance? TimeoutFailure (ex-cause ex)) |
| 38 | + :pass |
| 39 | + :fail)))))) |
| 40 | + |
| 41 | +(deftest the-test |
| 42 | + (testing "RetryPolicy defaults" |
| 43 | + (is (= :pass (exec {})))) |
| 44 | + (testing "Explicit unlimited" |
| 45 | + (is (= :pass (exec {:retry-options {:maximum-attempts 0}})))) |
| 46 | + (testing "Verify that setting maximum-attempts to a finite value is respected" |
| 47 | + (is (= :fail (exec {:retry-options {:maximum-attempts 1}}))))) |
0 commit comments