Skip to content

Commit

Permalink
Add semi-functional version (with :parallel) as the flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
alysbrooks committed Jul 21, 2021
1 parent 4495c94 commit 4a5b1b6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/kaocha/runner.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
20 changes: 18 additions & 2 deletions src/kaocha/test_suite.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
))
22 changes: 13 additions & 9 deletions src/kaocha/testable.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions src/kaocha/type/ns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion test/unit/kaocha/type/ns_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))))))
))

0 comments on commit 4a5b1b6

Please sign in to comment.