Skip to content

Commit 2ff8021

Browse files
committed
make shutdown test clj only
1 parent c45715a commit 2ff8021

4 files changed

Lines changed: 80 additions & 94 deletions

File tree

test/intemporal/shutdown_test.clj

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
(ns intemporal.shutdown-test
2+
(:require [clojure.test :as t :refer [deftest is testing]]
3+
[intemporal.store :as store]
4+
[intemporal.workflow :as w]
5+
[intemporal.test-utils :as tu]
6+
[matcher-combinators.test :refer [match?]])
7+
(:require [intemporal.macros :refer [stub-protocol defn-workflow]]
8+
[intemporal.test-utils :refer [with-result]]))
9+
10+
(t/use-fixtures :once tu/with-trace-logging)
11+
12+
(defprotocol MyActivities
13+
(foo [this a]))
14+
15+
(defrecord MyActivitiesImpl []
16+
MyActivities
17+
(foo [this a]
18+
(Thread/sleep 1000) :foo))
19+
20+
(defn-workflow my-workflow [k]
21+
(let [stub (stub-protocol MyActivities {})
22+
prr (foo stub :pr)]
23+
prr))
24+
25+
;;;; test proper
26+
27+
(deftest executor-shutdown-test
28+
(testing "failure: task validation fails"
29+
(let [mstore (store/make-store {})
30+
executor (w/start-poller! mstore {:protocols {`MyActivities (->MyActivitiesImpl)}
31+
:polling-ms 10})]
32+
33+
(testing "shutdown of ongoing workflow"
34+
;; give it some time so the poller can pick it up but just once
35+
(future
36+
(Thread/sleep 500)
37+
(w/shutdown executor 0))
38+
39+
(with-result [res (w/with-env {:store mstore}
40+
(my-workflow :ok))]
41+
42+
(is (instance? Exception res))
43+
(is (= "Operation timed out." (ex-message res)))
44+
45+
(testing "Workflow is not in failed state"
46+
(tu/print-tables mstore)
47+
48+
(testing "workflow task"
49+
(let [[w1] (store/list-tasks mstore)]
50+
(is (match? {:type :workflow :sym 'intemporal.shutdown-test/my-workflow- :state :pending} w1))
51+
52+
(testing "workflow events"
53+
(let [[e1 e2 e3] (store/list-events mstore)]
54+
(is (match? {:type :intemporal.workflow/invoke :sym 'intemporal.shutdown-test/my-workflow-} e1))
55+
(is (match? {:type :intemporal.protocol/invoke :sym 'intemporal.shutdown-test/foo} e2))
56+
(is (nil? e3))))))
57+
58+
(testing "workflow resumes"
59+
(let [executor (w/start-poller! mstore {:protocols {`MyActivities (->MyActivitiesImpl)}
60+
:polling-ms 10})]
61+
(store/reenqueue-pending-tasks mstore (constantly nil))
62+
(with-result [_ (Thread/sleep 2000)]
63+
64+
(tu/print-tables mstore)
65+
66+
(testing "workflow succeeded"
67+
(let [[w1] (store/list-tasks mstore)]
68+
(is (match? {:type :workflow :sym 'intemporal.shutdown-test/my-workflow- :state :success} w1))))
69+
70+
(w/shutdown executor 0))))))))))

test/intemporal/shutdown_test.cljc

Lines changed: 0 additions & 87 deletions
This file was deleted.

test/intemporal/test_utils.cljc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
[taoensso.telemere :as telemere]
1212
[net.cgrand.macrovich :as macros]
1313
[clojure.pprint :as pprint]))
14-
#?(:cljs (:require-macros [net.cgrand.macrovich :as macros]))
14+
#?(:cljs (:require-macros [net.cgrand.macrovich :as macros]
15+
[intemporal.test-utils :refer [with-result]]))
1516
#?(:clj (:import [java.util.concurrent TimeoutException])))
1617

1718
;;;;
@@ -100,17 +101,17 @@
100101
:clj
101102
`(let [~res (let [future# (future (do ~resbody))]
102103
(try
103-
(deref future# with-result-default-timeout (TimeoutException. "Operation timed out.")
104-
(catch Exception e#
105-
e#))))]
104+
(deref future# with-result-default-timeout (TimeoutException. "Operation timed out."))
105+
(catch Exception e# e#)))]
106106
~@body)
107107
:cljs
108108
`(t/async done#
109109
(js/setTimeout
110110
(fn []
111111
;; force wrap resbody in a deferred
112112
(p/finally (-> nil
113-
(p/then (fn [_#] (do ~resbody)))
113+
(p/then (fn [_#]
114+
(do ~resbody)))
114115
(p/timeout with-result-default-timeout))
115116
(fn [res# err#]
116117
(try

tests.edn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
{:plugins [:kaocha.plugin/randomize
33
:kaocha.plugin/filter
44
:kaocha.plugin/capture-output
5-
:kaocha.plugin/junit-xml
6-
:kaocha.plugin/cloverage]
5+
:kaocha.plugin/junit-xml]
6+
;:kaocha.plugin/cloverage]
7+
78
:reporter [kaocha.report/documentation]
89
:color? true
910
:fail-fast? false
@@ -28,6 +29,7 @@
2829
:test-paths ["test"]}
2930
{:id :unit-cljs
3031
:type :kaocha.type/cljs
32+
;:cljs/timeout 20000
3133
:ns-patterns ["-test$"]
3234
:source-paths ["src"]
3335
:test-paths ["test"]}]}

0 commit comments

Comments
 (0)