Skip to content

Commit

Permalink
Replace workarounds by locking require.
Browse files Browse the repository at this point in the history
  • Loading branch information
alysbrooks committed Sep 2, 2021
1 parent 1612336 commit 601f7fa
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/kaocha/testable.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
and `:line`."
nil)


(def REQUIRE_LOCK (Object.))

(defn add-desc [testable description]
(assoc testable ::desc
(str (name (::id testable)) " (" description ")")))

(defn- try-require [n]
(try
(require n)
(locking REQUIRE_LOCK
(require n))
true
(catch java.io.FileNotFoundException e
false)))
Expand All @@ -48,10 +52,10 @@
(try-require (symbol (name type)))))


(defn- try-assert-spec [type testable n]
(defn- retry-assert-spec [type testable n]
(let [ result (try (assert-spec type testable) (catch Exception _e false))]
(if (or result (<= n 1)) result
(try-assert-spec type testable (dec n))) ;otherwise, retry
(retry-assert-spec type testable (dec n))) ;otherwise, retry
))

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

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

0 comments on commit 601f7fa

Please sign in to comment.