Skip to content

Commit 0306180

Browse files
committed
Fix flaky tests over http
Closes #339
1 parent d577d3d commit 0306180

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

test/refactor_nrepl/artifacts_test.clj

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,41 @@
1818
(def clojure-artifacts ["clojure"])
1919
(def clojars-artifacts (resource "clojars-artifacts.edn"))
2020

21+
(defn retry-flaky
22+
"Retries a flaky fn `f`.
23+
24+
In our case the flakiness is outside of our control since Maven Central,
25+
Clojars, etc can always have hiccups."
26+
([f]
27+
(retry-flaky f 0))
28+
([f ^long attempts]
29+
(try
30+
(f)
31+
(catch Exception e
32+
;; give Maven a break:
33+
(Thread/sleep 12000)
34+
(if (< attempts 4)
35+
(retry-flaky f (inc attempts))
36+
(throw e))))))
37+
2138
(deftest get-mvn-artifacts!-test
22-
(is (> (count (#'artifacts/get-mvn-artifacts! "org.clojure"))
39+
(is (> (count (retry-flaky (fn []
40+
(#'artifacts/get-mvn-artifacts! "org.clojure"))))
2341
10)))
2442

2543
(deftest get-clojars-artifacts!-test
26-
(is (> (count (#'artifacts/get-clojars-artifacts!))
44+
(is (> (count (retry-flaky (fn []
45+
(#'artifacts/get-clojars-artifacts!))))
2746
1000)))
2847

2948
(deftest get-mvn-versions!-test
30-
(is (> (count (#'artifacts/get-mvn-versions! "org.clojure/clojure"))
49+
(is (> (count (retry-flaky (fn []
50+
(#'artifacts/get-mvn-versions! "org.clojure/clojure"))))
3151
20)))
3252

3353
(deftest get-clojars-versions!-test
34-
(is (> (count (#'artifacts/get-clojars-versions! "refactor-nrepl/refactor-nrepl"))
54+
(is (> (count (retry-flaky (fn []
55+
(#'artifacts/get-clojars-versions! "refactor-nrepl/refactor-nrepl"))))
3556
30)))
3657

3758
(deftest creates-a-map-of-artifacts

0 commit comments

Comments
 (0)