diff --git a/src/kaocha/testable.clj b/src/kaocha/testable.clj index 1089c7ae..56417e2a 100644 --- a/src/kaocha/testable.clj +++ b/src/kaocha/testable.clj @@ -232,14 +232,33 @@ (defn run-testables "Run a collection of testables, returning a result collection." [testables test-plan] - (let [load-error? (some ::load-error testables) + (let [load-error? (some ::load-error testables)] + (loop [result [] + [test & testables] testables] + (if test + (let [test (cond-> test + (and load-error? (not (::load-error test))) + (assoc ::skip true)) + r (run-testable test test-plan)] + (if (or (and *fail-fast?* (result/failed? r)) (::skip-remaining? r)) + (reduce into result [[r] testables]) + (recur (conj result r) testables))) + result)))) + + +(defn run-testables-parallel + "Run a collection of testables, returning a result collection." + [testables test-plan] +(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)] - (loop [result (ArrayBlockingQueue. 1024) + acc) + futures (map #(future (run-testable % test-plan)) testables)] + (println "Running in parallel!") + (comment (loop [result [] ;(ArrayBlockingQueue. 1024) [test & testables] testables] (if test (let [test (cond-> test @@ -247,9 +266,13 @@ (assoc ::skip true)) r (run-testable test test-plan)] (if (or (and *fail-fast?* (result/failed? r)) (::skip-remaining? r)) - (reduce put-return result [[r] testables]) - (recur (doto result (.put r)) testables))) - result)))) + ;(reduce put-return result [[r] testables]) + (reduce into result [[r] testables]) + ;(recur (doto result (.put r)) testables) + (recur (conj result r) testables))) + result))) + (map deref 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 433f775a..993e6b8d 100644 --- a/src/kaocha/type/ns.clj +++ b/src/kaocha/type/ns.clj @@ -18,7 +18,7 @@ ;; 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 test-plan)) + (fixture-fn #(swap! result testable/run-testables-parallel 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 b6f2decf..ec55b3cd 100644 --- a/test/unit/kaocha/type/ns_test.clj +++ b/test/unit/kaocha/type/ns_test.clj @@ -67,3 +67,38 @@ (:result (with-test-ctx {:fail-fast? true} (testable/run testable testable))))))) + +(require '[kaocha.config :as config]) + +(deftest run-test-parallel ;both tests currently test the parallel version but later... + (classpath/add-classpath "fixtures/f-tests") + + (let [testable (testable/load {:kaocha.testable/type :kaocha.type/clojure.test + :kaocha.testable/id :unit + :kaocha/ns-patterns ["-test$"] + :kaocha/source-paths ["src"] + :kaocha/test-paths ["fixtures/d-tests"] + :kaocha.filter/skip-meta [:kaocha/skip]}) + + #_(testable/load {:kaocha.testable/type :kaocha.type/ns + :kaocha.testable/id :foo.bar-test + :kaocha.testable/desc "foo.bar-test" + :kaocha.ns/name 'foo.bar-test})] + (is (match? {:kaocha.testable/type :kaocha.type/ns + :kaocha.testable/id :foo.bar-test + :kaocha.ns/name 'foo.bar-test + :kaocha.ns/ns ns? + :kaocha.result/tests [{:kaocha.testable/type :kaocha.type/var + :kaocha.testable/id :foo.bar-test/a-test + :kaocha.testable/desc "a-test" + :kaocha.var/name 'foo.bar-test/a-test + :kaocha.var/var var? + :kaocha.var/test fn? + :kaocha.result/count 1 + :kaocha.result/pass 1 + :kaocha.result/error 0 + :kaocha.result/pending 0 + :kaocha.result/fail 0}]} + (:result + (with-test-ctx {:fail-fast? true} + (testable/run testable testable)))))))