|  | 
|  | 1 | +;; Copyright © Manetu, Inc.  All rights reserved | 
|  | 2 | + | 
|  | 3 | +(ns temporal.test.retry-coherence | 
|  | 4 | +  (:require [clojure.test :refer :all] | 
|  | 5 | +            [taoensso.timbre :as log] | 
|  | 6 | +            [temporal.client.core :as c] | 
|  | 7 | +            [temporal.workflow :refer [defworkflow]] | 
|  | 8 | +            [temporal.activity :refer [defactivity] :as a] | 
|  | 9 | +            [temporal.test.utils :as t]) | 
|  | 10 | +  (:import [java.time Duration])) | 
|  | 11 | + | 
|  | 12 | +(use-fixtures :once t/wrap-service) | 
|  | 13 | + | 
|  | 14 | +(defactivity retry-activity | 
|  | 15 | +  [_ {:keys [mode]}] | 
|  | 16 | +  (let [{:keys [activity-id]} (a/get-info)] | 
|  | 17 | +    (log/info "retry-activity:" activity-id) | 
|  | 18 | +    (if-let [details (a/get-heartbeat-details)] | 
|  | 19 | +      (do | 
|  | 20 | +        (log/info "original activity-id:" activity-id "current activity-id:" details) | 
|  | 21 | +        (= activity-id details)) | 
|  | 22 | +      (do | 
|  | 23 | +        (a/heartbeat activity-id) | 
|  | 24 | +        (case mode | 
|  | 25 | +          :crash (throw (ex-info "synthetic crash" {})) | 
|  | 26 | +          :timeout (Thread/sleep 2000)))))) | 
|  | 27 | + | 
|  | 28 | +(defworkflow retry-workflow | 
|  | 29 | +  [args] | 
|  | 30 | +  @(a/invoke retry-activity args {:start-to-close-timeout (Duration/ofSeconds 1)})) | 
|  | 31 | + | 
|  | 32 | +(deftest the-test | 
|  | 33 | +  (testing "Verifies that a retriable crash has a stable activity-id" | 
|  | 34 | +    (let [workflow (t/create-workflow retry-workflow)] | 
|  | 35 | +      (c/start workflow {:mode :crash}) | 
|  | 36 | +      (is (-> workflow c/get-result deref true?)))) | 
|  | 37 | +  (testing "Verifies that a timeout retry has a stable activity-id" | 
|  | 38 | +    (let [workflow (t/create-workflow retry-workflow)] | 
|  | 39 | +      (c/start workflow {:mode :timeout}) | 
|  | 40 | +      (is (-> workflow c/get-result deref true?))))) | 
0 commit comments