Skip to content

Commit

Permalink
Randomize port on REPL start
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Dec 16, 2023
1 parent bd9368b commit 30379e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 18 additions & 0 deletions dev/user.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(ns user
(:require
[clojure.core.server :as server]
[clojure.java.io :as io]
[clojure.test :as t]
[clojure.tools.namespace.repl :as ns]))

Expand Down Expand Up @@ -31,6 +33,22 @@
(println (str "#p" (position) " " '~form " => (" (- (System/currentTimeMillis) t#) " ms) " res#)))
res#))

(defn -main [& args]
;; setup repl
(let [args (apply array-map args)
port (or
(some-> (get args "--port") parse-long)
(+ 1024 (rand-int 64512)))
file (io/file ".repl-port")]
(println "Started Server Socket REPL on port" port)
(spit file port)
(.deleteOnExit file)
(server/start-server
{:name "repl"
:port port
:accept 'clojure.core.server/repl
:server-daemon false})))

(defn test-all []
(reload)
(t/run-all-tests #"datascript\..*"))
3 changes: 1 addition & 2 deletions script/repl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
set -o errexit -o nounset -o pipefail
cd "`dirname $0`/.."

echo "Starting Socket REPL server on port 5555"
clj -A:1.11.1:dev:test:bench -X clojure.core.server/start-server :name repl :port 5555 :accept clojure.core.server/repl :server-daemon false
clj -A:1.11.1:dev:test:bench -M -m user

0 comments on commit 30379e6

Please sign in to comment.