Skip to content

Commit

Permalink
Drop support for JDK8
Browse files Browse the repository at this point in the history
Closes #615
  • Loading branch information
lread committed Aug 12, 2024
1 parent e58ff88 commit 579e40b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 52 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ A release with an intentional breaking changes is marked with:
// (adjust these in publish.clj as you see fit)
== Unreleased [minor breaking]

* Technically breaking
* Minor breaking
** {issue}615[#615]: Drop support for JDK8, Etaion now requires a minimum of JDK11
** {issue}613[#612]: Remove all support for long obsolete and long untested PhantomJS
({lread})
** {issue}467[#467]: Move to W3C WebDriver spec.
Expand Down
3 changes: 1 addition & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
:deps {org.clojure/clojure {:mvn/version "1.9.0"} ;; min clojure version
babashka/fs {:mvn/version "0.5.21"}
babashka/process {:mvn/version "0.5.22"}
clj-http/clj-http {:mvn/version "3.13.0"} ;; for jvm use
org.clj-commons/clj-http-lite {:mvn/version "1.0.13"} ;; for babashka use
org.babashka/http-client {:mvn/version "0.4.19"}
slingshot/slingshot {:mvn/version "0.12.2"}
cheshire/cheshire {:mvn/version "5.13.0"}
org.clojure/tools.cli {:mvn/version "1.1.230"}
Expand Down
2 changes: 1 addition & 1 deletion doc/01-user-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ There are two steps to installation:

==== For Clojure Users

Etaoin supports Clojure v1.9 and above.
Etaoin supports Clojure v1.9 and above on JDK11 and above.

Add the following into the `:dependencies` vector in your `project.clj` file:

Expand Down
13 changes: 6 additions & 7 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
[etaoin.query :as query]
[slingshot.slingshot :refer [throw+ try+]])
(:import
java.text.SimpleDateFormat
(java.text SimpleDateFormat)
(java.util Base64 Date)))

(set! *warn-on-reflection* true)
Expand Down Expand Up @@ -3463,12 +3463,11 @@
(let [[opts bind & body] (if (symbol? (second args))
args
(cons nil args))]
`(client/with-pool {}
(let [~bind (boot-driver ~type ~opts)]
(try
~@body
(finally
(quit ~bind)))))))
`(let [~bind (boot-driver ~type ~opts)]
(try
~@body
(finally
(quit ~bind))))))

(defmacro ^:no-doc with-headless-driver
{:arglists '([type opts? bind & body])}
Expand Down
44 changes: 16 additions & 28 deletions src/etaoin/impl/client.cljc
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
(ns ^:no-doc etaoin.impl.client
(:require
[babashka.http-client :as client]
[cheshire.core :as json]
[clojure.string :as str]
[clojure.tools.logging :as log]
[etaoin.impl.proc :as proc]
[etaoin.impl.util :as util]
#?(:bb [clj-http.lite.client :as client]
:clj [clj-http.client :as client])
[slingshot.slingshot :refer [throw+]]))

(set! *warn-on-reflection* true)
Expand All @@ -30,19 +29,10 @@
(def timeout (read-timeout))

(def default-api-params
#?(:bb
{:accept :json
:content-type :json
:socket-timeout (* 1000 timeout)
:conn-timeout (* 1000 timeout)
:debug false}
:clj
{:as :json
:accept :json
:content-type :json
:socket-timeout (* 1000 timeout)
:conn-timeout (* 1000 timeout)
:debug false}))
{:headers {:accept "application/json"
:content-type "application/json"}
:timeout (* 1000 timeout) ;; request timeout
:connect-timeout (* 1000 timeout)})

;;
;; helpers
Expand All @@ -58,10 +48,6 @@
(defn- get-url-path [items]
(str/join "/" (map url-item-str items)))

(defmacro with-pool [opt & body]
`(client/with-connection-pool ~opt
~@body))

(defn- parse-json [body]
(let [body* (str/replace body #"Invalid Command Method -" "")]
(try
Expand All @@ -84,7 +70,6 @@
;; if, by chance, something goes wrong while trying to realize process liveness
(assoc driver :process-liveness-ex ex))))


(defn http-request
"an isolated http-request to support mocking"
[params]
Expand All @@ -103,13 +88,12 @@
(format "http://%s:%s/%s" host port path))
params (cond-> (merge
default-api-params
{:url url
:method method
:throw-exceptions false})
{:uri url
:method method
:throw false})
(= :post method)
#?(:bb (assoc :body (.getBytes (json/generate-string (or payload {}))
"UTF-8"))
:clj (assoc :form-params (or payload {}))))
(assoc :body (.getBytes (json/generate-string (or payload {}))
"UTF-8")))
_ (log/debugf "%s %s %6s %s %s"
(name driver-type)
(if webdriver-url
Expand All @@ -131,8 +115,7 @@
{:exception ex}))]
(if (:exception resp)
(throw+ @error (:exception resp))
(let [body #?(:bb (some-> resp :body parse-json)
:clj (:body resp))
(let [body (some-> resp :body parse-json)
error (delay (assoc @error
:type :etaoin/http-error
:status (:status resp)
Expand All @@ -146,3 +129,8 @@

:else
body)))))

(comment
(http-request {:method :get :uri "https://clojure.org"})

)
2 changes: 1 addition & 1 deletion test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
(let [deadline (+ (System/currentTimeMillis) 15000)
test-url (test-server-url "test.html") ]
(loop []
(let [resp (try (client/http-request {:method :get :url test-url})
(let [resp (try (client/http-request {:method :get :uri test-url})
(catch Throwable _ :not-ready))]
(when (= :not-ready resp)
(if (< (System/currentTimeMillis) deadline)
Expand Down
45 changes: 33 additions & 12 deletions test/etaoin/unit/proc_test.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
(ns etaoin.unit.proc-test
(:require
[clojure.java.shell :as shell]
[clojure.string :as str]
[clojure.test :refer [deftest is]]
[etaoin.api :as e]
[etaoin.impl.client :as client]
[etaoin.impl.proc :as proc]
[etaoin.test-report]))
[etaoin.impl.util :as util]
[etaoin.test-report])
(:import (java.lang ProcessHandle)))

(defn all-processes []
(for [p (-> (ProcessHandle/allProcesses) .iterator iterator-seq)
:when (some-> p .info .command .isPresent)
:let [info (.info p)
command (-> info .command .get)
arguments (when (-> info .arguments .isPresent)
(->> info .arguments .get (into [])))
start-instant (-> info .startInstant .get)]]
{:pid (.pid p)
:is-alive (.isAlive p)
:start-instant start-instant
:handle p
:command command
:arguments arguments}))

(defn get-count-driver-instances
[drivername]
(if proc/windows?
(->> (all-processes)
(remove #(str/includes? (:command %) "\\scoop\\shims\\")) ;; exclude windows scoop shims
(filter #(str/includes? (:command %) drivername))
count)

#_(if proc/windows?
(let [instance-report (-> (shell/sh "powershell" "-command" (format "(Get-Process %s -ErrorAction SilentlyContinue).Path" drivername))
:out
str/split-lines)]
Expand All @@ -31,7 +52,7 @@
(get-count-driver-instances "geckodriver"))

(deftest test-process-forking-port-specified-is-in-use
(let [port 9997
(let [port (util/get-free-port)
process (proc/run ["chromedriver" (format "--port=%d" port)])]
(try
(e/wait-running {:port port :host "localhost"})
Expand All @@ -44,7 +65,7 @@
(proc/kill process)))))

(deftest test-process-forking-port-not-specified-so-random-port-is-picked
(let [port 9998
(let [port (util/get-free-port)
process (proc/run ["chromedriver" (format "--port=%d" port)])]
(try
(e/wait-running {:port port :host "localhost"})
Expand All @@ -58,7 +79,7 @@
(proc/kill process)))))

(deftest test-process-forking-connect-existing-webdriver-host
(let [port 9999
(let [port (util/get-free-port)
process (proc/run ["chromedriver" (format "--port=%d" port)])]
(try
(e/wait-running {:port port :host "localhost"})
Expand All @@ -70,7 +91,7 @@
(proc/kill process)))))

(deftest test-process-forking-connect-existing-webdriver-url
(let [port 9999
(let [port (util/get-free-port)
process (proc/run ["chromedriver" (format "--port=%d" port)])]
(try
(e/wait-running {:port port :host "localhost"})
Expand Down Expand Up @@ -112,9 +133,9 @@

(deftest http-exception-after-create-proc-now-dead
(let [orig-http-request client/http-request]
(with-redefs [client/http-request (fn [{:keys [method url] :as params}]
(with-redefs [client/http-request (fn [{:keys [method uri] :as params}]
;; allow create session through, fail on everything else
(if (and (= :post method) (str/ends-with? url "/session"))
(if (and (= :post method) (str/ends-with? uri "/session"))
(orig-http-request params)
(throw (ex-info "read timeout" {}))))]
(let [ex (try
Expand All @@ -135,9 +156,9 @@
(deftest http-error-after-create-proc-now-dead
;; unlikely, we know we just talked to the driver because it returned an http error, but for completeness
(let [orig-http-request client/http-request]
(with-redefs [client/http-request (fn [{:keys [method url] :as params}]
(with-redefs [client/http-request (fn [{:keys [method uri] :as params}]
;; allow create session through, fail on everything else
(if (and (= :post method) (str/ends-with? url "/session"))
(if (and (= :post method) (str/ends-with? uri "/session"))
(orig-http-request params)
{:status 418}))]
(let [ex (try
Expand All @@ -157,7 +178,7 @@
(is (= 0 (get-count-firefoxdriver-instances)))))))

(deftest test-cleanup-connect-existing-on-create-error
(let [port 9999
(let [port (util/get-free-port)
process (proc/run ["chromedriver" (format "--port=%d" port)])]
(try
(e/wait-running {:port port :host "localhost"})
Expand Down

0 comments on commit 579e40b

Please sign in to comment.