From 4a86cd0682d36e386666fbc5f4b230fc9e25370e Mon Sep 17 00:00:00 2001 From: lread Date: Sat, 16 Mar 2024 18:08:22 -0400 Subject: [PATCH] Find an available port for test server Was hardcoded to 8888, but this port can, of course, be in use for other things. --- test/etaoin/api_test.clj | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/etaoin/api_test.clj b/test/etaoin/api_test.clj index 64809732..2152954e 100644 --- a/test/etaoin/api_test.clj +++ b/test/etaoin/api_test.clj @@ -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) @@ -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)) @@ -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))