Skip to content

Commit 5dc641e

Browse files
committed
CLJS-2780: Async tests prematurely terminate in Node
While the current implementation of -tear-down in the Node REPL allows any pending (Node termination delaying) processing to finish, it doesn't allow for any further communication between the REPL and the Node process: It immediately destroys the Node-side socket while also discarding any REPL-side communication structures. This patch moves the code that discards REPL-side communication structures to occur after awaiting Node process termination so that any messages that are sent can be displayed. It also replaces the Node-side destroy call to an unref: This allows any lingering communication to occur, without causing the socket to keep the Node process alive.
1 parent 6048bc9 commit 5dc641e

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/main/clojure/cljs/repl/node.clj

+5-5
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,17 @@
240240
(load-javascript this provides url))
241241
(-tear-down [this]
242242
(swap! state update :listeners dec)
243-
(let [tname (thread-name)]
244-
(.remove results tname)
245-
(.remove outs tname)
246-
(.remove errs tname))
247243
(locking lock
248244
(when (zero? (:listeners @state))
249245
(let [sock @socket]
250246
(when-not (.isClosed (:socket sock))
251247
(write (:out sock) ":cljs/quit")
252248
(while (alive? @proc) (Thread/sleep 50))
253-
(close-socket sock)))))))
249+
(close-socket sock)))))
250+
(let [tname (thread-name)]
251+
(.remove results tname)
252+
(.remove outs tname)
253+
(.remove errs tname))))
254254

255255
(defn repl-env* [options]
256256
(let [{:keys [host port path debug-port]}

src/main/clojure/cljs/repl/node_repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var server = net.createServer(function (socket) {
6666

6767
if(":cljs/quit" == data) {
6868
server.close();
69-
socket.destroy();
69+
socket.unref();
7070
return;
7171
} else {
7272
try {

src/test/cljs_cli/cljs_cli/test.clj

+9
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,12 @@
115115
"-e" "(require 'left-pad)"
116116
"-e" "(left-pad 3 10 0)")
117117
(output-is "nil\n\"0000000003\""))))
118+
119+
(deftest test-cljs-2780
120+
(with-repl-env-filter #{"node" "nashorn"}
121+
(-> (cljs-main
122+
"-e" "(do (js/setTimeout #(prn :end) 500) nil)"
123+
"-e" ":begin")
124+
(output-is
125+
:begin
126+
:end))))

0 commit comments

Comments
 (0)