Skip to content

Commit

Permalink
tests: unit: retry-lauch: don't log to console
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lread committed May 3, 2024
1 parent 44a4749 commit 9bc36af
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions test/etaoin/unit/unit_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[babashka.fs :as fs]
[clojure.spec.alpha :as s]
[clojure.test :refer [deftest is testing]]
[clojure.tools.logging :as log]
[etaoin.api :as e]
[etaoin.ide.flow :as ide]
[etaoin.ide.impl.spec :as spec]
Expand Down Expand Up @@ -108,21 +109,35 @@

(deftest test-retry-launch
(testing "give up after max tries"
(let [run-calls (atom 0)]
(let [run-calls (atom 0)
warnings-logged (atom [])
ex (ex-info "firefox badness" {})]
(with-redefs
[etaoin.impl.proc/run (fn [_ _]
(swap! run-calls inc)
{:some :process})
e/running? (fn [_] (throw (ex-info "firefox badness" {})))]
e/running? (fn [_] (throw ex ))
log/log* (fn [_logger level _throwable message]
(swap! warnings-logged conj [level message]))]
(is (thrown-with-msg?
ExceptionInfo
#"gave up trying to launch :firefox after 8 tries"
(e/with-firefox {:webdriver-failed-launch-retries 7} driver
driver)))
(is (= 8 @run-calls)))))
(is (= 8 @run-calls) "run calls")
(is (= [[:warn "unexpected exception occurred launching :firefox, try 1 (of a max of 8)"]
[:warn "unexpected exception occurred launching :firefox, try 2 (of a max of 8)"]
[:warn "unexpected exception occurred launching :firefox, try 3 (of a max of 8)"]
[:warn "unexpected exception occurred launching :firefox, try 4 (of a max of 8)"]
[:warn "unexpected exception occurred launching :firefox, try 5 (of a max of 8)"]
[:warn "unexpected exception occurred launching :firefox, try 6 (of a max of 8)"]
[:warn "unexpected exception occurred launching :firefox, try 7 (of a max of 8)"]]
@warnings-logged) "warnings logged"))))
(testing "succeed before max tries"
(let [run-calls (atom 0)
succeed-when-calls 3]
succeed-when-calls 3
warnings-logged (atom [])
ex (ex-info "safari badness" {})]
(with-redefs
[etaoin.impl.proc/run (fn [_ _]
(swap! run-calls inc)
Expand All @@ -132,8 +147,10 @@
e/delete-session identity
e/running? (fn [_]
(if (< @run-calls succeed-when-calls)
(throw (ex-info "safari badness" {}))
(throw ex)
true))
log/log* (fn [_logger level _throwable message]
(swap! warnings-logged conj [level message]))
util/get-free-port (constantly 12345)]
;; safari driver has a default of 4 retries
(e/with-safari driver
Expand All @@ -146,7 +163,10 @@
:session "session-key"
:type :safari,
:url "http://127.0.0.1:12345"} driver)))
(is (= succeed-when-calls @run-calls))))))
(is (= succeed-when-calls @run-calls))
(is (= [[:warn "unexpected exception occurred launching :safari, try 1 (of a max of 5)"]
[:warn "unexpected exception occurred launching :safari, try 2 (of a max of 5)"]]
@warnings-logged) "warnings logged")))))

(deftest test-actions
(let [keyboard (-> (e/make-key-input)
Expand Down

0 comments on commit 9bc36af

Please sign in to comment.