Skip to content

Commit

Permalink
Find an available port for test server
Browse files Browse the repository at this point in the history
Was hardcoded to 8888, but this port can, of course, be in use for other
things.
  • Loading branch information
lread committed Mar 16, 2024
1 parent e6739b1 commit 4a86cd0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
[etaoin.api :as e]
[etaoin.impl.util :as util]
[etaoin.test-report :as test-report]
[slingshot.slingshot :refer [try+]]))
[slingshot.slingshot :refer [try+]])
(:import [java.net ServerSocket]))

(defn numeric? [val]
(or (instance? Double val)
Expand Down Expand Up @@ -50,7 +51,11 @@

(def ^:dynamic *driver*)

(def test-server-port 8888)
(defn- find-available-port []
(with-open [sock (ServerSocket. 0)]
(.getLocalPort sock)))

(def test-server-port (find-available-port))

(defn- test-server-url [path]
(format "http://localhost:%d/%s" test-server-port path))
Expand All @@ -77,7 +82,8 @@
(f))

(defn test-server [f]
(let [proc (p/process "bb test-server")]
(let [proc (p/process {:out :inherit :err :inherit}
"bb test-server --port" test-server-port)]
(f)
(p/destroy proc)
@proc))
Expand Down

0 comments on commit 4a86cd0

Please sign in to comment.