Skip to content

Commit

Permalink
wait for test-server ready in right place
Browse files Browse the repository at this point in the history
  • Loading branch information
lread committed Mar 16, 2024
1 parent 1f99736 commit 75f88b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 1 addition & 15 deletions script/test_server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,4 @@
(usage-help)
(do
(status/line :detail "Test server static dir: %s" (:dir opts))
(let [server (future (server/exec opts))
deadline (+ (System/currentTimeMillis) 15000)
test-url (str "http://localhost:" (:port opts)) ]
(loop []
(let [resp (try (client/get test-url)
(catch Throwable _ :not-ready))]
(when (= :not-ready resp)
(if (< (System/currentTimeMillis) deadline)
(do
(println "- waiting for test-server to be ready" test-url)
(Thread/sleep 1000)
(recur))
(throw (ex-info "Timed out waiting for ready test server" {}))))))
(println "Test server ready")
@server)))))
(server/exec opts)))))
14 changes: 14 additions & 0 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[clojure.test :refer [deftest is testing use-fixtures]]
[etaoin.api :as e]
[etaoin.impl.util :as util]
[etaoin.impl.client :as client]
[etaoin.test-report :as test-report]
[slingshot.slingshot :refer [try+]])
(:import [java.net ServerSocket]))
Expand Down Expand Up @@ -84,6 +85,19 @@
(defn test-server [f]
(let [proc (p/process {:out :inherit :err :inherit}
"bb test-server --port" test-server-port)]
(let [deadline (+ (System/currentTimeMillis) 15000)
test-url (test-server-url "test.html") ]
(loop []
(let [resp (try (client/http-request {:method :get :url test-url})
(catch Throwable _ :not-ready))]
(when (= :not-ready resp)
(if (< (System/currentTimeMillis) deadline)
(do
(println "- waiting for test-server to be ready at" test-url)
(Thread/sleep 1000)
(recur))
(throw (ex-info "Timed out waiting for ready test server" {}))))))
(println "Test server ready"))
(f)
(p/destroy proc)
@proc))
Expand Down

0 comments on commit 75f88b4

Please sign in to comment.