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

Add activity-id retry test #64

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?)))))