Skip to content

Commit 4a86cd0

Browse files
committed
Find an available port for test server
Was hardcoded to 8888, but this port can, of course, be in use for other things.
1 parent e6739b1 commit 4a86cd0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

test/etaoin/api_test.clj

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
[etaoin.api :as e]
1111
[etaoin.impl.util :as util]
1212
[etaoin.test-report :as test-report]
13-
[slingshot.slingshot :refer [try+]]))
13+
[slingshot.slingshot :refer [try+]])
14+
(:import [java.net ServerSocket]))
1415

1516
(defn numeric? [val]
1617
(or (instance? Double val)
@@ -50,7 +51,11 @@
5051

5152
(def ^:dynamic *driver*)
5253

53-
(def test-server-port 8888)
54+
(defn- find-available-port []
55+
(with-open [sock (ServerSocket. 0)]
56+
(.getLocalPort sock)))
57+
58+
(def test-server-port (find-available-port))
5459

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

7984
(defn test-server [f]
80-
(let [proc (p/process "bb test-server")]
85+
(let [proc (p/process {:out :inherit :err :inherit}
86+
"bb test-server --port" test-server-port)]
8187
(f)
8288
(p/destroy proc)
8389
@proc))

0 commit comments

Comments
 (0)