diff --git a/src/kaocha/runner.clj b/src/kaocha/runner.clj index d55bc2c9..4533555e 100644 --- a/src/kaocha/runner.clj +++ b/src/kaocha/runner.clj @@ -186,4 +186,5 @@ (try+ (System/exit (apply -main* args)) (catch :kaocha/early-exit {exit-code :kaocha/early-exit} + (shutdown-agents) (System/exit exit-code)))) diff --git a/src/kaocha/test_suite.clj b/src/kaocha/test_suite.clj index bfe45881..3c712357 100644 --- a/src/kaocha/test_suite.clj +++ b/src/kaocha/test_suite.clj @@ -2,12 +2,28 @@ (:require [clojure.test :as t] [kaocha.testable :as testable])) +(defn deref-recur [testables] + (cond (future? testables) (deref testables) + (vector? testables) (doall (mapv deref-recur testables)) + (seq? testables) (deref-recur (into [] (doall testables))) + (contains? testables :kaocha.test-plan/tests) + (update testables :kaocha.test-plan/tests deref-recur) + (contains? testables :kaocha.result/tests) + (update testables :kaocha.result/tests deref-recur) + :else testables)) + (defn run [testable test-plan] (t/do-report {:type :begin-test-suite}) - (let [results (testable/run-testables (:kaocha.test-plan/tests testable) test-plan) + (let [results (deref-recur (testable/run-testables (:kaocha.test-plan/tests testable) test-plan) ) + ;; _ (println "Done derefing") + ;; __ (println (class results)) + ;; __ (println (class (last results))) + ;; (doall (map #(if (future? %) (deref %) %) + ;; (testable/run-testables (:kaocha.test-plan/tests testable) test-plan))) testable (-> testable (dissoc :kaocha.test-plan/tests) (assoc :kaocha.result/tests results))] (t/do-report {:type :end-test-suite :kaocha/testable testable}) - testable)) + (doto testable tap>) + )) diff --git a/src/kaocha/testable.clj b/src/kaocha/testable.clj index b010fa51..1826b73e 100644 --- a/src/kaocha/testable.clj +++ b/src/kaocha/testable.clj @@ -232,6 +232,10 @@ (defn run-testables "Run a collection of testables, returning a result collection." [testables test-plan] + (print "run-testables got a collection of size" (count testables) + " the first of which is " + (:kaocha.testable/type (first testables)) + ) (let [load-error? (some ::load-error testables)] (loop [result [] [test & testables] testables] @@ -249,15 +253,16 @@ (defn run-testables-parallel "Run a collection of testables, returning a result collection." [testables test-plan] + + (print "run-testables-parallel got a collection of size" (count testables)) (let [load-error? (some ::load-error testables) ;; results (watch/make-queue) - put-return (fn [acc value] - (if (instance? BlockingQueue value) - (.drainTo value acc) - (.put acc value)) - acc) - futures (map #(future (run-testable % test-plan)) testables)] - (println "Running in parallel!") + ;; put-return (fn [acc value] + ;; (if (instance? BlockingQueue value) + ;; (.drainTo value acc) + ;; (.put acc value)) + ;; acc) + futures (doall (map #(future (do (println "Firing off future!" (Thread/currentThread)) (binding [*config* (dissoc *config* :parallel)] (run-testable % test-plan)))) testables))] (comment (loop [result [] ;(ArrayBlockingQueue. 1024) [test & testables] testables] (if test @@ -271,8 +276,7 @@ ;(recur (doto result (.put r)) testables) (recur (conj result r) testables))) result))) - (map deref futures) - )) + futures)) (defn test-seq [testable] (cond->> (mapcat test-seq (remove ::skip (or (:kaocha/tests testable) diff --git a/src/kaocha/type/ns.clj b/src/kaocha/type/ns.clj index ef95095a..e409e2eb 100644 --- a/src/kaocha/type/ns.clj +++ b/src/kaocha/type/ns.clj @@ -17,8 +17,16 @@ (defn run-tests [testable test-plan fixture-fn] ;; It's not guaranteed the the fixture-fn returns the result of calling the ;; tests function, so we need to put it in a box for reference. - (let [result (atom (:kaocha.test-plan/tests testable))] - (fixture-fn #(swap! result testable/run-testables-parallel test-plan)) + ;; (println (keys test-plan)) + ;; (println (:kaocha.testable/meta test-plan)) + (let [result (atom (:kaocha.test-plan/tests testable)) + run-testables-fn (if (:parallel testable/*config*) + testable/run-testables-parallel + testable/run-testables) + #_testable/run-testables + + ] + (fixture-fn #(swap! result run-testables-fn test-plan)) @result)) (defmethod testable/-load :kaocha.type/ns [testable] diff --git a/test/unit/kaocha/type/ns_test.clj b/test/unit/kaocha/type/ns_test.clj index ec55b3cd..cfe71e13 100644 --- a/test/unit/kaocha/type/ns_test.clj +++ b/test/unit/kaocha/type/ns_test.clj @@ -77,7 +77,7 @@ :kaocha.testable/id :unit :kaocha/ns-patterns ["-test$"] :kaocha/source-paths ["src"] - :kaocha/test-paths ["fixtures/d-tests"] + :kaocha/test-paths ["fixtures/f-tests"] :kaocha.filter/skip-meta [:kaocha/skip]}) #_(testable/load {:kaocha.testable/type :kaocha.type/ns @@ -101,4 +101,10 @@ :kaocha.result/fail 0}]} (:result (with-test-ctx {:fail-fast? true} + (testable/run testable testable))))) + (is (not (nil? (:result + (binding [testable/*config* (assoc testable/*config* :parallel true)] + (with-test-ctx {:fail-fast? true + :parallel true } (testable/run testable testable))))))) + ))