             {:keys [status errors]} resp]
         (is (= 400 status))
         (is (re-matches #"The paging depth \(page_num \* page_size\) of \[\d*?\] exceeds the limit of \d*?.*?"
-                        (first errors)))))))
+                        (first errors))))))
 
-(deftest search-with-page-size
-  (create-collections)
   (testing "Search with page_size."
     (let [{:keys [refs]} (search/find-refs :collection {:page_size 5})]
       (is (= 5 (count refs)))))
   (testing "Search with large page_size."
     (let [{:keys [refs]} (search/find-refs :collection {:page_size 100})]
       (is (= collection-count (count refs)))))
+  (testing "all revision page size"
+    (let [{:keys [refs]} (search/find-refs :collection {:page_size 5 :all-revisions true})]
+      (is (= 5 (count refs)))))
   (testing "page_size less than zero."
     (let [resp (search/find-refs :collection {:page_size -1})
           {:keys [status errors]} resp]

            [cmr.system-int-test.utils.search-util :as search]
            [cmr.system-int-test.utils.index-util :as index]
            [cmr.system-int-test.data2.collection :as dc]
            [cmr.system-int-test.data2.core :as d2c]
            [cmr.search.services.parameters.parameter-validation :as pm]))

(def prov1-collection-count 10)
(def prov2-collection-count 15)

(def collection-count (+ prov2-collection-count prov1-collection-count))

(defn create-collections
  "Set up the fixtures for tests."
  []
  (dotimes [n prov1-collection-count]
    (d2c/ingest "PROV1" (dc/collection)))
  (dotimes [n prov2-collection-count]
    (d2c/ingest "PROV2" (dc/collection)))
  (index/wait-until-indexed))

(use-fixtures :each (ingest/reset-fixture {"provguid1" "PROV1" "provguid2" "PROV2"}))

(deftest search-with-page-size-and-page-num
  (create-collections)
  (testing "Exceeded page depth (page-num * page-size)"
    (let [page-size 10
          page-num 1000000000]

  (are [hits params]
       (= hits (:hits (search/find-refs :collection params)))
       collection-count {}
       revision-count {:all-revisions true}
       0 {:provider "NONE"}
       prov1-collection-count {:provider "PROV1"}
       prov2-collection-count {:provider "PROV2"}))

(defn get-concept-id-revision-id
  "Returns a tuple of concept id and revision id. Works with references or collections."
  [c]
  [(or (:concept-id c) (:id c))
   (:revision-id c)])

(defn concept-id->sequence-number
  "Returns the sequence number used for sorting in elastic in leau of concept-id"
  [concept-id]
  (:sequence-number (concepts/parse-concept-id concept-id)))

(defn sort-collections-all-revisions
  "Sorts a list of collections using the same default sort as search for all revisions."
  [collections]
  (sort-by identity
           (fn [c1 c2]
             (let [et1 (:entry-title c1)
                   et2 (:entry-title c2)
                   p1 (:provider-id c1)
                   p2 (:provider-id c2)
                   seq1 (concept-id->sequence-number (:concept-id c1))
                   seq2 (concept-id->sequence-number (:concept-id c2))]
               (cond
                 (not= et1 et2) (compare et1 et2)
                 (not= p1 p2) (compare p1 p2)
                 (not= seq1 seq2) (compare seq1 seq2)
                 :else (compare (:revision-id c2) (:revision-id c1)))))
           collections))

(defn select-page
  "Manually selects a page of collections."
  [collections page-num page-size]
  (nth (partition-all page-size collections) (dec page-num)))


(deftest search-all-revisions-with-page-num
  (let [all-collections (sort-collections-all-revisions (create-collections))]

    (testing "Find everything on one big page"
      (let [{:keys [refs]} (search/find-refs :collection {:page_size 1000
                                                          :all-revisions true})]
        (is (= (map get-concept-id-revision-id all-collections)
               (map get-concept-id-revision-id refs)))))

    (testing "Find by page 1"
      (let [{:keys [refs]} (search/find-refs :collection {:page_size 12
                                                          :page_num 1
                                                          :all-revisions true})]
        (is (= (map get-concept-id-revision-id (select-page all-collections 1 12))
               (map get-concept-id-revision-id refs)))))

    (testing "Find by page 2"
      (let [{:keys [refs]} (search/find-refs :collection {:page_size 12
                                                          :page_num 2
                                                          :all-revisions true})]
        (is (= (map get-concept-id-revision-id (select-page all-collections 2 12))
               (map get-concept-id-revision-id refs)))))))


(deftest search-with-page-num
  (let [provider-id "PROV1"
