Skip to content

Commit

Permalink
Add activity-id retry test
Browse files Browse the repository at this point in the history
Signed-off-by: Greg Haskins <greg@manetu.com>
  • Loading branch information
ghaskins committed Jul 25, 2024
1 parent f29d440 commit 0256b25
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dev-resources/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
(log/info "greet-activity:" args)
(str "Hi, " name))

(defworkflow child-workflow
(defworkflow user-child-workflow
[{names :names :as args}]
(log/info "child-workflow:" names)
(for [name names]
@(a/invoke greet-activity {:name name})))

(defworkflow parent-workflow
(defworkflow user-parent-workflow
[args]
(log/info "parent-workflow:" args)
@(w/invoke child-workflow args (merge default-workflow-options {:workflow-id "child-workflow"})))
@(w/invoke user-child-workflow args (merge default-workflow-options {:workflow-id "child-workflow"})))

(defn create-temporal-client
"Creates a new temporal client if the old one does not exist"
Expand Down Expand Up @@ -78,4 +78,4 @@
(comment
(do (create-temporal-client)
(create-temporal-worker @client)
(execute-workflow @client parent-workflow {:names ["Hanna" "Bob" "Tracy" "Felix"]})))
(execute-workflow @client user-parent-workflow {:names ["Hanna" "Bob" "Tracy" "Felix"]})))
40 changes: 40 additions & 0 deletions test/temporal/test/retry_coherence.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
;; Copyright © Manetu, Inc. All rights reserved

(ns temporal.test.retry-coherence
(:require [clojure.test :refer :all]
[taoensso.timbre :as log]
[temporal.client.core :as c]
[temporal.workflow :refer [defworkflow]]
[temporal.activity :refer [defactivity] :as a]
[temporal.test.utils :as t])
(:import [java.time Duration]))

(use-fixtures :once t/wrap-service)

(defactivity retry-activity
[_ {:keys [mode]}]
(let [{:keys [activity-id]} (a/get-info)]
(log/info "retry-activity:" activity-id)
(if-let [details (a/get-heartbeat-details)]
(do
(log/info "original activity-id:" activity-id "current activity-id:" details)
(= activity-id details))
(do
(a/heartbeat activity-id)
(case mode
:crash (throw (ex-info "synthetic crash" {}))
:timeout (Thread/sleep 2000))))))

(defworkflow retry-workflow
[args]
@(a/invoke retry-activity args {:start-to-close-timeout (Duration/ofSeconds 1)}))

(deftest the-test
(testing "Verifies that a retriable crash has a stable activity-id"
(let [workflow (t/create-workflow retry-workflow)]
(c/start workflow {:mode :crash})
(is (-> workflow c/get-result deref true?))))
(testing "Verifies that a timeout retry has a stable activity-id"
(let [workflow (t/create-workflow retry-workflow)]
(c/start workflow {:mode :timeout})
(is (-> workflow c/get-result deref true?)))))

0 comments on commit 0256b25

Please sign in to comment.