Skip to content

Commit 30ad2e9

Browse files
ikappakibbatsov
authored andcommitted
Check that client is connected to nREPL server
1 parent b2c3d3c commit 30ad2e9

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

test/integration/integration-tests.el

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ Remove the temp directory at the end of evaluation."
4343
(error
4444
(message ":with-temp-dir-error :cannot-remove-temp-dir %S" err))))))
4545

46+
(defun nrepl-client-connected?-ref-make! ()
47+
"Return a reference to indicate when the client is connected to nREPL server.
48+
This is done by adding a hook to `cider-connected-hook` and is only active
49+
in the scope of the current buffer."
50+
(let (connected?)
51+
(add-hook 'cider-connected-hook
52+
(lambda ()
53+
(setq connected? t))
54+
nil
55+
;; only set in the current buffer scope.
56+
t)))
57+
58+
4659
(describe "jack in"
4760
;; See "bb" case for basic commentary
4861
;;
@@ -63,8 +76,15 @@ Remove the temp directory at the end of evaluation."
6376

6477
(unwind-protect
6578
;; jack in and get repl buffer
66-
(let* ((nrepl-proc (cider-jack-in-clj '()))
79+
(let* ((client-connected?* (nrepl-client-connected?-ref-make!))
80+
(nrepl-proc (cider-jack-in-clj '()))
6781
(nrepl-buf (process-buffer nrepl-proc)))
82+
83+
;; wait until the client has successfully connected to the
84+
;; nREPL server.
85+
(nrepl-tests-sleep-until 5 client-connected?*)
86+
(expect client-connected?*)
87+
6888
;; give it some time to setup the clj REPL
6989
(nrepl-tests-sleep-until 5 (cider-repls 'clj nil))
7090

@@ -113,8 +133,11 @@ Remove the temp directory at the end of evaluation."
113133
(with-temp-buffer
114134
(setq-local default-directory project-dir)
115135
(unwind-protect
116-
(let* ((nrepl-proc (cider-jack-in-clj `()))
136+
(let* ((client-connected?* (nrepl-client-connected?-ref-make!))
137+
(nrepl-proc (cider-jack-in-clj `()))
117138
(nrepl-buf (process-buffer nrepl-proc)))
139+
(nrepl-tests-sleep-until 5 client-connected?*)
140+
(expect client-connected?*)
118141

119142
;; high duration since on windows it takes a long time to startup
120143
(nrepl-tests-sleep-until 90 (cider-repls 'clj nil))
@@ -150,8 +173,11 @@ Remove the temp directory at the end of evaluation."
150173
(with-temp-buffer
151174
(setq-local default-directory project-dir)
152175
(unwind-protect
153-
(let* ((nrepl-proc (cider-jack-in-clj `()))
176+
(let* ((client-connected?* (nrepl-client-connected?-ref-make!))
177+
(nrepl-proc (cider-jack-in-clj `()))
154178
(nrepl-buf (process-buffer nrepl-proc)))
179+
(nrepl-tests-sleep-until 5 client-connected?*)
180+
(expect client-connected?*)
155181
(nrepl-tests-sleep-until 90 (cider-repls 'clj nil))
156182
(let ((repl-buffer (cider-current-repl))
157183
(eval-err '())
@@ -197,8 +223,11 @@ Remove the temp directory at the end of evaluation."
197223
(with-temp-buffer
198224
(setq-local default-directory project-dir)
199225
(unwind-protect
200-
(let* ((nrepl-proc (cider-jack-in-cljs '(:cljs-repl-type shadow)))
226+
(let* ((client-connected?* (nrepl-client-connected?-ref-make!))
227+
(nrepl-proc (cider-jack-in-cljs '(:cljs-repl-type shadow)))
201228
(nrepl-buf (process-buffer nrepl-proc)))
229+
(nrepl-tests-sleep-until 5 client-connected?*)
230+
(expect client-connected?*)
202231
(nrepl-tests-sleep-until 120 (cider-repls 'cljs nil))
203232
(expect (cider-repls 'cljs nil) :not :to-be nil)
204233
(let ((repl-buffer (cider-current-repl))

test/nrepl-client-tests.el

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@
159159
;; server has reported its endpoint
160160
(nrepl-tests-sleep-until 2 server-endpoint)
161161
(expect server-endpoint :not :to-be nil)
162-
(expect (plist-get (process-plist server-process) :cider--nrepl-server-ready)
163-
:to-equal t)
162+
164163
(condition-case error-details
165164
;; start client process
166165
(let* ((client-buffer (get-buffer-create ":nrepl-lifecycle/client"))
@@ -183,12 +182,10 @@
183182
(delete-process process-client)
184183

185184
;; server process has been signalled
186-
(nrepl-tests-sleep-until 4 (member (process-status server-process)
187-
'(exit signal)))
188-
(expect (let ((status (process-status server-process)))
189-
(if (eq system-type 'windows-nt)
190-
(eq status 'exit)
191-
(eq status 'signal)))))
185+
(nrepl-tests-sleep-until 4 (eq (process-status server-process)
186+
'signal))
187+
(expect (process-status server-process)
188+
:to-equal 'signal))
192189
(error
193190
;; there may be some useful information in the nrepl buffer on error
194191
(when-let ((nrepl-error-buffer (get-buffer "*nrepl-error*")))

test/utils/nrepl-tests-utils.el

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
;;; Code:
2727

28-
(require 'nrepl-client)
29-
3028
(defmacro nrepl-tests-log/init! (enable? name log-filename &optional clean?)
3129
"Create a NAME/log! elisp function to log messages to LOG-FILENAME,
3230
taking the same arguments as `message'. Messages are appended to
@@ -99,19 +97,5 @@ calling process."
9997
;; invoke mock server
10098
" -l test/nrepl-server-mock.el -f nrepl-server-mock-start"))
10199

102-
(defun nrepl-start-mock-server-process ()
103-
"Start and return the mock nrepl server process."
104-
(let* ((up? nil)
105-
(server-process (nrepl-start-server-process
106-
default-directory
107-
(nrepl-server-mock-invocation-string)
108-
(lambda (server-buffer)
109-
(setq up? t)))))
110-
;; server has reported its endpoint
111-
(nrepl-tests-sleep-until 2 up?)
112-
server-process))
113100

114101
(provide 'nrepl-tests-utils)
115-
116-
;;; nrepl-tests-utils.el ends here
117-

0 commit comments

Comments
 (0)