|
3 | 3 | [babashka.fs :as fs]
|
4 | 4 | [clojure.spec.alpha :as s]
|
5 | 5 | [clojure.test :refer [deftest is testing]]
|
| 6 | + [clojure.tools.logging :as log] |
6 | 7 | [etaoin.api :as e]
|
7 | 8 | [etaoin.ide.flow :as ide]
|
8 | 9 | [etaoin.ide.impl.spec :as spec]
|
|
108 | 109 |
|
109 | 110 | (deftest test-retry-launch
|
110 | 111 | (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" {})] |
112 | 115 | (with-redefs
|
113 | 116 | [etaoin.impl.proc/run (fn [_ _]
|
114 | 117 | (swap! run-calls inc)
|
115 | 118 | {: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]))] |
117 | 122 | (is (thrown-with-msg?
|
118 | 123 | ExceptionInfo
|
119 | 124 | #"gave up trying to launch :firefox after 8 tries"
|
120 | 125 | (e/with-firefox {:webdriver-failed-launch-retries 7} driver
|
121 | 126 | 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")))) |
123 | 136 | (testing "succeed before max tries"
|
124 | 137 | (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" {})] |
126 | 141 | (with-redefs
|
127 | 142 | [etaoin.impl.proc/run (fn [_ _]
|
128 | 143 | (swap! run-calls inc)
|
|
132 | 147 | e/delete-session identity
|
133 | 148 | e/running? (fn [_]
|
134 | 149 | (if (< @run-calls succeed-when-calls)
|
135 |
| - (throw (ex-info "safari badness" {})) |
| 150 | + (throw ex) |
136 | 151 | true))
|
| 152 | + log/log* (fn [_logger level _throwable message] |
| 153 | + (swap! warnings-logged conj [level message])) |
137 | 154 | util/get-free-port (constantly 12345)]
|
138 | 155 | ;; safari driver has a default of 4 retries
|
139 | 156 | (e/with-safari driver
|
|
146 | 163 | :session "session-key"
|
147 | 164 | :type :safari,
|
148 | 165 | :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"))))) |
150 | 170 |
|
151 | 171 | (deftest test-actions
|
152 | 172 | (let [keyboard (-> (e/make-key-input)
|
|
0 commit comments