Skip to content

Commit

Permalink
Ok partitioning does need to sort namespaces (but not vars)
Browse files Browse the repository at this point in the history
  • Loading branch information
camsaul committed Sep 6, 2024
1 parent c131029 commit 8ecb623
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
26 changes: 10 additions & 16 deletions src/mb/hawk/partition.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@
(var? x) (namespace (symbol x))
:else nil))

(defn- ensure-test-namespaces-are-contiguous
"Make sure `test-vars` have all the tests for each namespace next to one another so when we split we can do so without
splitting in the middle of a namespace. Does not otherwise change the order of the tests or namespaces."
(defn- sort-tests-by-namespace
"The test runner normally sorts the namespaces before running tests, so we should do the same before we partition things
if we want them to make sense. Preserve the order of the vars inside each namespace."
[test-vars]
(let [namespace->sort-position (into {}
(map-indexed
(fn [i nmspace]
[nmspace i]))
(distinct (map namespace* test-vars)))
test-var->sort-position (into {}
(map-indexed
(fn [i varr]
[varr i]))
test-vars)]
(sort-by (juxt #(namespace->sort-position (namespace* %))
test-var->sort-position)
(let [test-var->sort-position (into {}
(map-indexed
(fn [i varr]
[varr i]))
test-vars)]
(sort-by (juxt namespace* test-var->sort-position)
test-vars)))

(defn- namespace->num-tests
Expand Down Expand Up @@ -118,7 +112,7 @@
grouped together."
[num-partitions test-vars]
{:post [(= (count %) num-partitions)]}
(let [test-vars (ensure-test-namespaces-are-contiguous test-vars)
(let [test-vars (sort-tests-by-namespace test-vars)
test-var->partition (make-test-var->partition num-partitions test-vars)]
(reduce
(fn [m test-var]
Expand Down
12 changes: 6 additions & 6 deletions test/mb/hawk/partition_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@
(partition-tests* 2 '[a/test-1 a/test-2 a/test-3 b/test-1])))))

(deftest ^:parallel partition-preserve-order-test
(testing "Partitioning should preserve order of namespaces and vars"
(is (= '{0 [b/test-1 b/test-2 b/test-3]
1 [a/test-1 a/test-3 a/test-2]}
(testing "Partitioning should sort namespaces but preserve order of vars"
(is (= '{0 [a/test-1 a/test-3 a/test-2]
1 [b/test-1 b/test-2 b/test-3]}
(partition-tests* 2 '[b/test-1 b/test-2 b/test-3 a/test-1 a/test-3 a/test-2])))))

(deftest ^:parallel partition-test
(is (= {0 [#'mb.hawk.core-test/find-tests-test
#'mb.hawk.core-test/exclude-tags-test]
1 [#'mb.hawk.speak-test/speak-results-test]
2 [#'mb.hawk.parallel-test/ns-parallel-test
#'mb.hawk.parallel-test/var-not-parallel-test]}
1 [#'mb.hawk.parallel-test/ns-parallel-test
#'mb.hawk.parallel-test/var-not-parallel-test]
2 [#'mb.hawk.speak-test/speak-results-test]}
(into (sorted-map)
(map (fn [i]
[i (hawk/find-tests-with-options
Expand Down

0 comments on commit 8ecb623

Please sign in to comment.