From 601f7fac190c1742879fd4ab1e23e101018d6352 Mon Sep 17 00:00:00 2001 From: Alys Brooks Date: Fri, 27 Aug 2021 00:22:17 -0500 Subject: [PATCH] Replace workarounds by locking require. --- src/kaocha/testable.clj | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/kaocha/testable.clj b/src/kaocha/testable.clj index d500c230..ee0e99ac 100644 --- a/src/kaocha/testable.clj +++ b/src/kaocha/testable.clj @@ -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))) @@ -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 @@ -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)))))) @@ -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]