|
| 1 | +(ns temporal.test.start-delay |
| 2 | + (:require |
| 3 | + [clojure.test :refer :all] |
| 4 | + [temporal.client.core :as c] |
| 5 | + [temporal.test.utils :as t] |
| 6 | + [temporal.workflow :refer [defworkflow]]) |
| 7 | + (:import |
| 8 | + [io.temporal.client WorkflowStub] |
| 9 | + [java.time Duration Instant] |
| 10 | + [java.time.temporal ChronoUnit TemporalAmount])) |
| 11 | + |
| 12 | +(set! *warn-on-reflection* true) |
| 13 | + |
| 14 | +(use-fixtures :once t/wrap-service) |
| 15 | + |
| 16 | +(defworkflow delay-workflow |
| 17 | + [_args] |
| 18 | + :ok) |
| 19 | + |
| 20 | +(defn create [options] |
| 21 | + (let [options (assoc options :task-queue t/task-queue) |
| 22 | + wf (c/create-workflow (t/get-client) delay-workflow options)] |
| 23 | + (c/start wf nil) |
| 24 | + wf)) |
| 25 | + |
| 26 | +(defn get-execution-time ^Instant [workflow] |
| 27 | + (.. ^WorkflowStub (:stub workflow) |
| 28 | + describe |
| 29 | + getExecutionTime)) |
| 30 | + |
| 31 | +(defn from-now ^Instant [^TemporalAmount delay] |
| 32 | + (.. (Instant/now) |
| 33 | + (plus delay) |
| 34 | + (truncatedTo ChronoUnit/SECONDS))) |
| 35 | + |
| 36 | +(deftest the-test |
| 37 | + (testing "Verifies that the workflow got delayed" |
| 38 | + (let [start-delay (Duration/ofHours 2) |
| 39 | + expected (from-now start-delay) |
| 40 | + wf (create {:workflow-id "delayed-workflow" |
| 41 | + :start-delay start-delay}) |
| 42 | + execution-time (get-execution-time wf)] |
| 43 | + (is (.isBefore expected execution-time))))) |
| 44 | + |
| 45 | +(deftest no-delay |
| 46 | + (testing "Verifies that the workflow is not delayed per default" |
| 47 | + (let [wf (create {:workflow-id "non-delayed-workflow"}) |
| 48 | + execution-time (get-execution-time wf) |
| 49 | + now (from-now (Duration/ofSeconds 1))] |
| 50 | + (is (.isAfter now execution-time))))) |
0 commit comments