Skip to content

Commit

Permalink
Work from pairing session with Arne.
Browse files Browse the repository at this point in the history
  • Loading branch information
alysbrooks committed Jun 23, 2021
1 parent 461c4b6 commit 74d1f81
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
35 changes: 29 additions & 6 deletions src/kaocha/testable.clj
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,47 @@
(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
(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 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)
Expand Down
2 changes: 1 addition & 1 deletion src/kaocha/type/ns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
35 changes: 35 additions & 0 deletions test/unit/kaocha/type/ns_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))))

0 comments on commit 74d1f81

Please sign in to comment.