Skip to content

Commit 4a5b1b6

Browse files
committed
Add semi-functional version (with :parallel) as the flag.
1 parent 4495c94 commit 4a5b1b6

5 files changed

Lines changed: 49 additions & 14 deletions

File tree

src/kaocha/runner.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,5 @@
186186
(try+
187187
(System/exit (apply -main* args))
188188
(catch :kaocha/early-exit {exit-code :kaocha/early-exit}
189+
(shutdown-agents)
189190
(System/exit exit-code))))

src/kaocha/test_suite.clj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,28 @@
22
(:require [clojure.test :as t]
33
[kaocha.testable :as testable]))
44

5+
(defn deref-recur [testables]
6+
(cond (future? testables) (deref testables)
7+
(vector? testables) (doall (mapv deref-recur testables))
8+
(seq? testables) (deref-recur (into [] (doall testables)))
9+
(contains? testables :kaocha.test-plan/tests)
10+
(update testables :kaocha.test-plan/tests deref-recur)
11+
(contains? testables :kaocha.result/tests)
12+
(update testables :kaocha.result/tests deref-recur)
13+
:else testables))
14+
515
(defn run [testable test-plan]
616
(t/do-report {:type :begin-test-suite})
7-
(let [results (testable/run-testables (:kaocha.test-plan/tests testable) test-plan)
17+
(let [results (deref-recur (testable/run-testables (:kaocha.test-plan/tests testable) test-plan) )
18+
;; _ (println "Done derefing")
19+
;; __ (println (class results))
20+
;; __ (println (class (last results)))
21+
;; (doall (map #(if (future? %) (deref %) %)
22+
;; (testable/run-testables (:kaocha.test-plan/tests testable) test-plan)))
823
testable (-> testable
924
(dissoc :kaocha.test-plan/tests)
1025
(assoc :kaocha.result/tests results))]
1126
(t/do-report {:type :end-test-suite
1227
:kaocha/testable testable})
13-
testable))
28+
(doto testable tap>)
29+
))

src/kaocha/testable.clj

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@
232232
(defn run-testables
233233
"Run a collection of testables, returning a result collection."
234234
[testables test-plan]
235+
(print "run-testables got a collection of size" (count testables)
236+
" the first of which is "
237+
(:kaocha.testable/type (first testables))
238+
)
235239
(let [load-error? (some ::load-error testables)]
236240
(loop [result []
237241
[test & testables] testables]
@@ -249,15 +253,16 @@
249253
(defn run-testables-parallel
250254
"Run a collection of testables, returning a result collection."
251255
[testables test-plan]
256+
257+
(print "run-testables-parallel got a collection of size" (count testables))
252258
(let [load-error? (some ::load-error testables)
253259
;; results (watch/make-queue)
254-
put-return (fn [acc value]
255-
(if (instance? BlockingQueue value)
256-
(.drainTo value acc)
257-
(.put acc value))
258-
acc)
259-
futures (map #(future (run-testable % test-plan)) testables)]
260-
(println "Running in parallel!")
260+
;; put-return (fn [acc value]
261+
;; (if (instance? BlockingQueue value)
262+
;; (.drainTo value acc)
263+
;; (.put acc value))
264+
;; acc)
265+
futures (doall (map #(future (do (println "Firing off future!" (Thread/currentThread)) (binding [*config* (dissoc *config* :parallel)] (run-testable % test-plan)))) testables))]
261266
(comment (loop [result [] ;(ArrayBlockingQueue. 1024)
262267
[test & testables] testables]
263268
(if test
@@ -271,8 +276,7 @@
271276
;(recur (doto result (.put r)) testables)
272277
(recur (conj result r) testables)))
273278
result)))
274-
(map deref futures)
275-
))
279+
futures))
276280

277281
(defn test-seq [testable]
278282
(cond->> (mapcat test-seq (remove ::skip (or (:kaocha/tests testable)

src/kaocha/type/ns.clj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@
1717
(defn run-tests [testable test-plan fixture-fn]
1818
;; It's not guaranteed the the fixture-fn returns the result of calling the
1919
;; tests function, so we need to put it in a box for reference.
20-
(let [result (atom (:kaocha.test-plan/tests testable))]
21-
(fixture-fn #(swap! result testable/run-testables-parallel test-plan))
20+
;; (println (keys test-plan))
21+
;; (println (:kaocha.testable/meta test-plan))
22+
(let [result (atom (:kaocha.test-plan/tests testable))
23+
run-testables-fn (if (:parallel testable/*config*)
24+
testable/run-testables-parallel
25+
testable/run-testables)
26+
#_testable/run-testables
27+
28+
]
29+
(fixture-fn #(swap! result run-testables-fn test-plan))
2230
@result))
2331

2432
(defmethod testable/-load :kaocha.type/ns [testable]

test/unit/kaocha/type/ns_test.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
:kaocha.testable/id :unit
7878
:kaocha/ns-patterns ["-test$"]
7979
:kaocha/source-paths ["src"]
80-
:kaocha/test-paths ["fixtures/d-tests"]
80+
:kaocha/test-paths ["fixtures/f-tests"]
8181
:kaocha.filter/skip-meta [:kaocha/skip]})
8282

8383
#_(testable/load {:kaocha.testable/type :kaocha.type/ns
@@ -101,4 +101,10 @@
101101
:kaocha.result/fail 0}]}
102102
(:result
103103
(with-test-ctx {:fail-fast? true}
104+
(testable/run testable testable)))))
105+
(is (not (nil? (:result
106+
(binding [testable/*config* (assoc testable/*config* :parallel true)]
107+
(with-test-ctx {:fail-fast? true
108+
:parallel true }
104109
(testable/run testable testable)))))))
110+
))

0 commit comments

Comments
 (0)