Skip to content

Commit 74d1f81

Browse files
committed
Work from pairing session with Arne.
1 parent 461c4b6 commit 74d1f81

3 files changed

Lines changed: 65 additions & 7 deletions

File tree

src/kaocha/testable.clj

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,24 +232,47 @@
232232
(defn run-testables
233233
"Run a collection of testables, returning a result collection."
234234
[testables test-plan]
235-
(let [load-error? (some ::load-error testables)
235+
(let [load-error? (some ::load-error testables)]
236+
(loop [result []
237+
[test & testables] testables]
238+
(if test
239+
(let [test (cond-> test
240+
(and load-error? (not (::load-error test)))
241+
(assoc ::skip true))
242+
r (run-testable test test-plan)]
243+
(if (or (and *fail-fast?* (result/failed? r)) (::skip-remaining? r))
244+
(reduce into result [[r] testables])
245+
(recur (conj result r) testables)))
246+
result))))
247+
248+
249+
(defn run-testables-parallel
250+
"Run a collection of testables, returning a result collection."
251+
[testables test-plan]
252+
(let [load-error? (some ::load-error testables)
236253
;; results (watch/make-queue)
237254
put-return (fn [acc value]
238255
(if (instance? BlockingQueue value)
239256
(.drainTo value acc)
240257
(.put acc value))
241-
acc)]
242-
(loop [result (ArrayBlockingQueue. 1024)
258+
acc)
259+
futures (map #(future (run-testable % test-plan)) testables)]
260+
(println "Running in parallel!")
261+
(comment (loop [result [] ;(ArrayBlockingQueue. 1024)
243262
[test & testables] testables]
244263
(if test
245264
(let [test (cond-> test
246265
(and load-error? (not (::load-error test)))
247266
(assoc ::skip true))
248267
r (run-testable test test-plan)]
249268
(if (or (and *fail-fast?* (result/failed? r)) (::skip-remaining? r))
250-
(reduce put-return result [[r] testables])
251-
(recur (doto result (.put r)) testables)))
252-
result))))
269+
;(reduce put-return result [[r] testables])
270+
(reduce into result [[r] testables])
271+
;(recur (doto result (.put r)) testables)
272+
(recur (conj result r) testables)))
273+
result)))
274+
(map deref futures)
275+
))
253276

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

src/kaocha/type/ns.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
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.
2020
(let [result (atom (:kaocha.test-plan/tests testable))]
21-
(fixture-fn #(swap! result testable/run-testables test-plan))
21+
(fixture-fn #(swap! result testable/run-testables-parallel test-plan))
2222
@result))
2323

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

test/unit/kaocha/type/ns_test.clj

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,38 @@
6767
(:result
6868
(with-test-ctx {:fail-fast? true}
6969
(testable/run testable testable)))))))
70+
71+
(require '[kaocha.config :as config])
72+
73+
(deftest run-test-parallel ;both tests currently test the parallel version but later...
74+
(classpath/add-classpath "fixtures/f-tests")
75+
76+
(let [testable (testable/load {:kaocha.testable/type :kaocha.type/clojure.test
77+
:kaocha.testable/id :unit
78+
:kaocha/ns-patterns ["-test$"]
79+
:kaocha/source-paths ["src"]
80+
:kaocha/test-paths ["fixtures/d-tests"]
81+
:kaocha.filter/skip-meta [:kaocha/skip]})
82+
83+
#_(testable/load {:kaocha.testable/type :kaocha.type/ns
84+
:kaocha.testable/id :foo.bar-test
85+
:kaocha.testable/desc "foo.bar-test"
86+
:kaocha.ns/name 'foo.bar-test})]
87+
(is (match? {:kaocha.testable/type :kaocha.type/ns
88+
:kaocha.testable/id :foo.bar-test
89+
:kaocha.ns/name 'foo.bar-test
90+
:kaocha.ns/ns ns?
91+
:kaocha.result/tests [{:kaocha.testable/type :kaocha.type/var
92+
:kaocha.testable/id :foo.bar-test/a-test
93+
:kaocha.testable/desc "a-test"
94+
:kaocha.var/name 'foo.bar-test/a-test
95+
:kaocha.var/var var?
96+
:kaocha.var/test fn?
97+
:kaocha.result/count 1
98+
:kaocha.result/pass 1
99+
:kaocha.result/error 0
100+
:kaocha.result/pending 0
101+
:kaocha.result/fail 0}]}
102+
(:result
103+
(with-test-ctx {:fail-fast? true}
104+
(testable/run testable testable)))))))

0 commit comments

Comments
 (0)