|
50 | 50 | (try-require (symbol (namespace type))))
|
51 | 51 | (try-require (symbol (name type)))))
|
52 | 52 |
|
53 |
| -(defn- retry-assert-spec [type testable n] |
54 |
| - (let [result (try (assert-spec type testable) (catch Exception _e false))] |
55 |
| - (if (or result (<= n 1)) result |
56 |
| - (retry-assert-spec type testable (dec n))) ;otherwise, retry |
57 |
| -)) |
58 |
| - |
59 |
| -(defn deref-recur [testables] |
60 |
| - (cond (future? testables) (deref testables) |
61 |
| - (vector? testables) (doall (mapv deref-recur testables)) |
62 |
| - (seq? testables) (deref-recur (into [] (doall testables))) |
63 |
| - (contains? testables :kaocha.test-plan/tests) |
64 |
| - (update testables :kaocha.test-plan/tests deref-recur) |
65 |
| - (contains? testables :kaocha.result/tests) |
66 |
| - (update testables :kaocha.result/tests deref-recur) |
67 |
| - :else testables)) |
68 |
| - |
69 | 53 | (defn- load-type+validate
|
70 | 54 | "Try to load a testable type, and validate it both to be a valid generic testable, and a valid instance given the type.
|
71 | 55 |
|
|
163 | 147 | result))))
|
164 | 148 |
|
165 | 149 | (spec/fdef run
|
166 |
| - :args (spec/cat :testable :kaocha.test-plan/testable |
167 |
| - :test-plan :kaocha/test-plan) |
168 |
| - :ret :kaocha.result/testable) |
| 150 | + :args (spec/cat :testable :kaocha.test-plan/testable |
| 151 | + :test-plan :kaocha/test-plan) |
| 152 | + :ret :kaocha.result/testable) |
169 | 153 |
|
170 | 154 | (defn load-testables
|
171 | 155 | "Load a collection of testables, returning a test-plan collection"
|
|
241 | 225 |
|
242 | 226 | (defn try-run-testable [test test-plan n]
|
243 | 227 | (let [result (try (run-testable test test-plan) (catch Exception _e false))]
|
244 |
| - (if (or result (> n 1)) result ;success or last try, return |
245 |
| - (try-run-testable test test-plan (dec n))) ;otherwise retry |
246 |
| -)) |
247 |
| - |
| 228 | + (if (or result (> n 1)) |
| 229 | + ;; success or last try, return |
| 230 | + result |
| 231 | + ;; otherwise retry |
| 232 | + (try-run-testable test test-plan (dec n))))) |
248 | 233 |
|
249 | 234 | (defn run-testables-serial
|
250 | 235 | "Run a collection of testables, returning a result collection."
|
251 | 236 | [testables test-plan]
|
252 |
| - (doall testables) |
253 |
| - #_(print "run-testables got a collection of size" (count testables) |
254 |
| - " the first of which is " |
255 |
| - (:kaocha.testable/type (first testables))) |
256 | 237 | (let [load-error? (some ::load-error testables)]
|
257 | 238 | (loop [result []
|
258 | 239 | [test & testables] testables]
|
|
262 | 243 | (assoc ::skip true))
|
263 | 244 | r (run-testable test test-plan)]
|
264 | 245 | (if (or (and *fail-fast?* (result/failed? r)) (::skip-remaining? r))
|
265 |
| - (reduce into result [[r] testables]) |
| 246 | + (into (conj result r) testables) |
266 | 247 | (recur (conj result r) testables)))
|
267 | 248 | result))))
|
268 | 249 |
|
|
273 | 254 | :group-name (.getName (.getThreadGroup thread))}))
|
274 | 255 |
|
275 | 256 | (defn run-testables-parallel
|
276 |
| - "Run a collection of testables, returning a result collection." |
| 257 | + "Run a collection of testables in parallel, returning a result collection." |
277 | 258 | [testables test-plan]
|
278 |
| - (doall testables) |
279 | 259 | (let [load-error? (some ::load-error testables)
|
280 |
| - types (set (:parallel-children-exclude *config*)) |
281 |
| - suites (:parallel-suites-exclude *config*) |
282 |
| - futures (map #(do |
| 260 | + futures (doall |
| 261 | + (map (fn [t] |
283 | 262 | (future
|
284 |
| - (binding [*config* |
285 |
| - (cond-> *config* |
286 |
| - (contains? types (:kaocha.testable/type %)) (dissoc :parallel) |
287 |
| - (and (hierarchy/suite? %) (contains? suites (:kaocha.testable/desc %))) (dissoc :parallel) |
288 |
| - true (update :levels (fn [x] (if (nil? x) 1 (inc x)))))] |
289 |
| - (run-testable (assoc % ::thread (current-thread-info) ) test-plan)))) |
290 |
| - testables)] |
291 |
| - (comment (loop [result [] ;(ArrayBlockingQueue. 1024) |
292 |
| - [test & testables] testables] |
293 |
| - (if test |
294 |
| - (let [test (cond-> test |
295 |
| - (and load-error? (not (::load-error test))) |
296 |
| - (assoc ::skip true)) |
297 |
| - r (run-testable test test-plan)] |
298 |
| - (if (or (and *fail-fast?* (result/failed? r)) (::skip-remaining? r)) |
299 |
| - ;(reduce put-return result [[r] testables]) |
300 |
| - (reduce into result [[r] testables]) |
301 |
| - ;(recur (doto result (.put r)) testables) |
302 |
| - (recur (conj result r) testables))) |
303 |
| - result))) |
304 |
| - (deref-recur futures))) |
| 263 | + (run-testable (assoc t ::thread-info (current-thread-info)) test-plan))) |
| 264 | + testables))] |
| 265 | + (doall (map deref futures)))) |
305 | 266 |
|
306 | 267 | (defn run-testables
|
| 268 | + "Original run-testables, left for backwards compatibility, and still usable for |
| 269 | + test types that don't want to opt-in to parallelization. Generally |
| 270 | + implementations should move to [[run-testables-parent]]." |
307 | 271 | [testables test-plan]
|
308 |
| - (if (:parallel *config*) |
309 |
| - (doall (run-testables-parallel testables test-plan)) |
310 |
| - (run-testables-serial testables test-plan))) |
| 272 | + (run-testables-serial testables test-plan)) |
| 273 | + |
| 274 | +(defn run-testables-parent |
| 275 | + "Test type implementations should call this in their [[-run]] method, rather |
| 276 | + than [[run-testables]], so we can inspect the parent and parent metadata to |
| 277 | + decide if the children should get parallelized." |
| 278 | + [parent test-plan] |
| 279 | + (let [testables (:kaocha.test-plan/tests parent)] |
| 280 | + (if (or (true? (:kaocha/parallelize? (::meta parent))) ; explicit opt-in via metadata |
| 281 | + (and (:kaocha/parallelize? test-plan) ; enable parallelization in top-level config |
| 282 | + (or (::parallelizable? parent) ; test type has opted in, children are considered parallelizable |
| 283 | + (:kaocha/parallelize? parent)) ; or we're at the top level, suites are parallelizable. Can also be used as an explicit override/opt-in |
| 284 | + (not (false? (:kaocha/parallelize? (::meta parent)))))) ; explicit opt-out via metadata |
| 285 | + (run-testables-parallel testables test-plan) |
| 286 | + (run-testables-serial testables test-plan)))) |
311 | 287 |
|
312 | 288 | (defn test-seq [testable]
|
313 | 289 | (cond->> (mapcat test-seq (remove ::skip (or (:kaocha/tests testable)
|
|
320 | 296 |
|
321 | 297 | (defn test-seq-with-skipped
|
322 | 298 | [testable]
|
323 |
| - "Create a seq of all tests, including any skipped tests. |
| 299 | + "Create a seq of all tests, including any skipped tests. |
324 | 300 |
|
325 | 301 | Typically you want to look at `test-seq` instead."
|
326 | 302 | (cond->> (mapcat test-seq (or (:kaocha/tests testable)
|
327 |
| - (:kaocha.test-plan/tests testable) |
328 |
| - (:kaocha.result/tests testable))) |
| 303 | + (:kaocha.test-plan/tests testable) |
| 304 | + (:kaocha.result/tests testable))) |
329 | 305 | ;; When calling test-seq on the top level test-plan/result, don't include
|
330 | 306 | ;; the outer map. When running on an actual testable, do include it.
|
331 | 307 | (:kaocha.testable/id testable)
|
|
0 commit comments