Skip to content

Commit 601f7fa

Browse files
committed
Replace workarounds by locking require.
1 parent 1612336 commit 601f7fa

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/kaocha/testable.clj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@
3030
and `:line`."
3131
nil)
3232

33+
34+
(def REQUIRE_LOCK (Object.))
35+
3336
(defn add-desc [testable description]
3437
(assoc testable ::desc
3538
(str (name (::id testable)) " (" description ")")))
3639

3740
(defn- try-require [n]
3841
(try
39-
(require n)
42+
(locking REQUIRE_LOCK
43+
(require n))
4044
true
4145
(catch java.io.FileNotFoundException e
4246
false)))
@@ -48,10 +52,10 @@
4852
(try-require (symbol (name type)))))
4953

5054

51-
(defn- try-assert-spec [type testable n]
55+
(defn- retry-assert-spec [type testable n]
5256
(let [ result (try (assert-spec type testable) (catch Exception _e false))]
5357
(if (or result (<= n 1)) result
54-
(try-assert-spec type testable (dec n))) ;otherwise, retry
58+
(retry-assert-spec type testable (dec n))) ;otherwise, retry
5559
))
5660

5761
(defn- load-type+validate
@@ -67,7 +71,7 @@
6771
(let [type (::type testable)]
6872
(try-load-third-party-lib type)
6973
(try
70-
(try-assert-spec type testable 3)
74+
(assert-spec type testable)
7175
(catch Exception e
7276
(output/warn (format "Could not load %s. This is a known bug in parallelization.\n%s" type e))))))
7377

@@ -284,7 +288,7 @@
284288
(println (:parallel *config*) \space (.getName (Thread/currentThread)))
285289
(future
286290
;(do #_(println "Firing off future!" (Thread/currentThread)) )
287-
(binding [*config* (dissoc *config* :parallel)] (try-run-testable % test-plan 3))))
291+
(binding [*config* (dissoc *config* :parallel)] (run-testable % test-plan))))
288292
testables))]
289293
(comment (loop [result [] ;(ArrayBlockingQueue. 1024)
290294
[test & testables] testables]

0 commit comments

Comments
 (0)