Skip to content

Commit 0256b25

Browse files
committed
Add activity-id retry test
Signed-off-by: Greg Haskins <[email protected]>
1 parent f29d440 commit 0256b25

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

dev-resources/utils.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
(log/info "greet-activity:" args)
2626
(str "Hi, " name))
2727

28-
(defworkflow child-workflow
28+
(defworkflow user-child-workflow
2929
[{names :names :as args}]
3030
(log/info "child-workflow:" names)
3131
(for [name names]
3232
@(a/invoke greet-activity {:name name})))
3333

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

3939
(defn create-temporal-client
4040
"Creates a new temporal client if the old one does not exist"
@@ -78,4 +78,4 @@
7878
(comment
7979
(do (create-temporal-client)
8080
(create-temporal-worker @client)
81-
(execute-workflow @client parent-workflow {:names ["Hanna" "Bob" "Tracy" "Felix"]})))
81+
(execute-workflow @client user-parent-workflow {:names ["Hanna" "Bob" "Tracy" "Felix"]})))
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)