From 0256b2552c78168eb13348a308844d09aca75b20 Mon Sep 17 00:00:00 2001 From: Greg Haskins Date: Mon, 15 Jul 2024 17:08:30 -0400 Subject: [PATCH] Add activity-id retry test Signed-off-by: Greg Haskins --- dev-resources/utils.clj | 8 +++--- test/temporal/test/retry_coherence.clj | 40 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 test/temporal/test/retry_coherence.clj diff --git a/dev-resources/utils.clj b/dev-resources/utils.clj index 708e8dc..fed4261 100644 --- a/dev-resources/utils.clj +++ b/dev-resources/utils.clj @@ -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" @@ -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"]}))) diff --git a/test/temporal/test/retry_coherence.clj b/test/temporal/test/retry_coherence.clj new file mode 100644 index 0000000..f2126d0 --- /dev/null +++ b/test/temporal/test/retry_coherence.clj @@ -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?)))))