Skip to content

Commit 868f3db

Browse files
committed
Add workarounds for now.
1 parent 22cf0d8 commit 868f3db

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/kaocha/testable.clj

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
(try-require (symbol (namespace type))))
4848
(try-require (symbol (name type)))))
4949

50+
51+
(defn- try-assert-spec [type testable n]
52+
(let [ result (try (assert-spec type testable) (catch Exception _e false))]
53+
(if (or result (<= n 1)) result
54+
(try-assert-spec type testable (dec n))) ;otherwise, retry
55+
))
56+
5057
(defn- load-type+validate
5158
"Try to load a testable type, and validate it both to be a valid generic testable, and a valid instance given the type.
5259
@@ -60,11 +67,9 @@
6067
(let [type (::type testable)]
6168
(try-load-third-party-lib type)
6269
(try
63-
(assert-spec type testable)
70+
(try-assert-spec type testable 3)
6471
(catch Exception e
65-
(prn e)
66-
)
67-
)))
72+
(output/warn (format "Could not load %s. This is a known bug in parallelization.\n%s" type e))))))
6873

6974
(defmulti -load
7075
"Given a testable, load the specified tests, producing a test-plan."
@@ -130,10 +135,8 @@
130135
Also performs validation, and lazy loading of the testable type's
131136
implementation."
132137
[testable test-plan]
133-
;; (println (class testable))
138+
(load-type+validate testable)
134139
(binding [*current-testable* testable]
135-
;; (println (:kaocha.testable/id *current-testable*))
136-
(load-type+validate testable)
137140
(let [run (plugin/run-hook :kaocha.hooks/wrap-run -run test-plan)
138141
result (run testable test-plan)]
139142
(if-let [history history/*history*]
@@ -220,6 +223,13 @@
220223
(run % test-plan)
221224
(plugin/run-hook :kaocha.hooks/post-test % test-plan)))))
222225

226+
227+
(defn try-run-testable [test test-plan n]
228+
(let [ result (try (run-testable test test-plan) (catch Exception _e false))]
229+
(if (or result (> n 1)) result ;success or last try, return
230+
(try-run-testable test test-plan (dec n))) ;otherwise retry
231+
))
232+
223233
(defn f [acc value]
224234
(if (instance? BlockingQueue value)
225235
(.drainTo value acc)
@@ -274,7 +284,7 @@
274284
(println (:parallel *config*) \space (.getName (Thread/currentThread)))
275285
(future
276286
;(do #_(println "Firing off future!" (Thread/currentThread)) )
277-
(binding [*config* (dissoc *config* :parallel)] (run-testable % test-plan))))
287+
(binding [*config* (dissoc *config* :parallel)] (try-run-testable % test-plan 3))))
278288
testables))]
279289
(comment (loop [result [] ;(ArrayBlockingQueue. 1024)
280290
[test & testables] testables]

0 commit comments

Comments
 (0)