diff --git a/src/kale/create.clj b/src/kale/create.clj index c9ed0df..6a2653f 100644 --- a/src/kale/create.clj +++ b/src/kale/create.clj @@ -147,11 +147,14 @@ [endpoint cluster-id] (let [start-time (t/now) update-time (atom (t/now)) - wait-time (fn [target] (t/in-minutes (t/interval target (t/now))))] - (while (and (= "NOT_AVAILABLE" - (:solr_cluster_status (rnr/get-cluster endpoint - cluster-id))) + wait-time (fn [target] (t/in-minutes (t/interval target (t/now)))) + available-count (atom 0)] + (while (and (< @available-count 5) (< (wait-time start-time) 30)) + (if (= "READY" + (:solr_cluster_status (rnr/get-cluster endpoint cluster-id))) + (swap! available-count inc) + (reset! available-count 0)) (print ".") (when (>= (wait-time @update-time) 5) ;; Inform the user that we're still waiting diff --git a/test/kale/create_test.clj b/test/kale/create_test.clj index 5e2311e..53ce8a2 100644 --- a/test/kale/create_test.clj +++ b/test/kale/create_test.clj @@ -260,10 +260,23 @@ (with-redefs [rnr/get-cluster (fn [_ _] (swap! counter inc) - (if (= @counter 4) + (if (> @counter 3) {:solr_cluster_status "READY"} {:solr_cluster_status "NOT_AVAILABLE"}))] - (is (= (str "..." new-line) + (is (= (str "........" new-line) + (with-out-str + (sut/wait-for-cluster {} "CLUSTER-ID"))))))) + +(deftest wait-for-cluster-restart-availability-count + (let [counter (atom 0)] + (with-redefs [rnr/get-cluster + (fn [_ _] + (swap! counter inc) + (if (or (> @counter 3) + (= @counter 6)) + {:solr_cluster_status "READY"} + {:solr_cluster_status "NOT_AVAILABLE"}))] + (is (= (str "........" new-line) (with-out-str (sut/wait-for-cluster {} "CLUSTER-ID"))))))) @@ -272,12 +285,13 @@ (with-redefs [rnr/get-cluster (fn [_ _] (swap! counter inc) - (if (= @counter 4) + (if (> @counter 3) {:solr_cluster_status "READY"} {:solr_cluster_status "NOT_AVAILABLE"})) - in-minutes (fn [_] (if (< @counter 3) 0 5))] + in-minutes (fn [_] (if (= @counter 3) 5 0))] (is (= (str "..." new-line "Still waiting on cluster to become ready." new-line + "....." new-line) (with-out-str (sut/wait-for-cluster {} "CLUSTER-ID")))))))