Skip to content

Commit 086e590

Browse files
committed
tests: unit: retry-lauch: don't log to console
I keep forgetting that log output to the terminal is normal for this test and sometimes assume something has gone wrong. So mock the logger and also test that it is getting called as expected.
1 parent c699552 commit 086e590

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

test/etaoin/unit/unit_test.clj

+26-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[babashka.fs :as fs]
44
[clojure.spec.alpha :as s]
55
[clojure.test :refer [deftest is testing]]
6+
[clojure.tools.logging :as log]
67
[etaoin.api :as e]
78
[etaoin.ide.flow :as ide]
89
[etaoin.ide.impl.spec :as spec]
@@ -108,21 +109,35 @@
108109

109110
(deftest test-retry-launch
110111
(testing "give up after max tries"
111-
(let [run-calls (atom 0)]
112+
(let [run-calls (atom 0)
113+
warnings-logged (atom [])
114+
ex (ex-info "firefox badness" {})]
112115
(with-redefs
113116
[etaoin.impl.proc/run (fn [_ _]
114117
(swap! run-calls inc)
115118
{:some :process})
116-
e/running? (fn [_] (throw (ex-info "firefox badness" {})))]
119+
e/running? (fn [_] (throw ex ))
120+
log/log* (fn [_logger level _throwable message]
121+
(swap! warnings-logged conj [level message]))]
117122
(is (thrown-with-msg?
118123
ExceptionInfo
119124
#"gave up trying to launch :firefox after 8 tries"
120125
(e/with-firefox {:webdriver-failed-launch-retries 7} driver
121126
driver)))
122-
(is (= 8 @run-calls)))))
127+
(is (= 8 @run-calls) "run calls")
128+
(is (= [[:warn "unexpected exception occurred launching :firefox, try 1 (of a max of 8)"]
129+
[:warn "unexpected exception occurred launching :firefox, try 2 (of a max of 8)"]
130+
[:warn "unexpected exception occurred launching :firefox, try 3 (of a max of 8)"]
131+
[:warn "unexpected exception occurred launching :firefox, try 4 (of a max of 8)"]
132+
[:warn "unexpected exception occurred launching :firefox, try 5 (of a max of 8)"]
133+
[:warn "unexpected exception occurred launching :firefox, try 6 (of a max of 8)"]
134+
[:warn "unexpected exception occurred launching :firefox, try 7 (of a max of 8)"]]
135+
@warnings-logged) "warnings logged"))))
123136
(testing "succeed before max tries"
124137
(let [run-calls (atom 0)
125-
succeed-when-calls 3]
138+
succeed-when-calls 3
139+
warnings-logged (atom [])
140+
ex (ex-info "safari badness" {})]
126141
(with-redefs
127142
[etaoin.impl.proc/run (fn [_ _]
128143
(swap! run-calls inc)
@@ -132,8 +147,10 @@
132147
e/delete-session identity
133148
e/running? (fn [_]
134149
(if (< @run-calls succeed-when-calls)
135-
(throw (ex-info "safari badness" {}))
150+
(throw ex)
136151
true))
152+
log/log* (fn [_logger level _throwable message]
153+
(swap! warnings-logged conj [level message]))
137154
util/get-free-port (constantly 12345)]
138155
;; safari driver has a default of 4 retries
139156
(e/with-safari driver
@@ -146,7 +163,10 @@
146163
:session "session-key"
147164
:type :safari,
148165
:url "http://127.0.0.1:12345"} driver)))
149-
(is (= succeed-when-calls @run-calls))))))
166+
(is (= succeed-when-calls @run-calls))
167+
(is (= [[:warn "unexpected exception occurred launching :safari, try 1 (of a max of 5)"]
168+
[:warn "unexpected exception occurred launching :safari, try 2 (of a max of 5)"]]
169+
@warnings-logged) "warnings logged")))))
150170

151171
(deftest test-actions
152172
(let [keyboard (-> (e/make-key-input)

0 commit comments

Comments
 (0)