Skip to content

Commit 372eeab

Browse files
ikappakibbatsov
authored andcommitted
Use improved test poller for siblings test while increasing timeout
The `nrepl-tests-poll-until` poller is a copy from the one found in integration utils and replaces `nrepl-tests-sleep-until`.
1 parent b3a9b32 commit 372eeab

File tree

3 files changed

+67
-60
lines changed

3 files changed

+67
-60
lines changed

test/cider-tests.el

+50-41
Original file line numberDiff line numberDiff line change
@@ -591,58 +591,67 @@
591591
(describe "sets nrepl client local vars correctly"
592592
(it "for nbb project"
593593
(let* ((server-process (nrepl-start-mock-server-process))
594-
(server-buffer (process-buffer server-process))
595-
(client-buffer (cider-connect-sibling-cljs
596-
'(:cljs-repl-type nbb) server-buffer)))
597-
;; native cljs REPL
598-
(expect (buffer-local-value 'cider-repl-type client-buffer)
599-
:to-equal 'cljs)
600-
(expect (buffer-local-value 'cider-repl-cljs-upgrade-pending client-buffer)
601-
:to-equal nil)
602-
(expect (buffer-local-value 'cider-repl-init-function client-buffer)
603-
:to-be nil)
604-
(delete-process (get-buffer-process client-buffer))))
594+
(server-buffer (process-buffer server-process)))
595+
;; wait for the connection to be established
596+
(nrepl-tests-poll-until (local-variable-p 'nrepl-endpoint server-buffer) 5)
597+
(let ((client-buffer (cider-connect-sibling-cljs
598+
'(:cljs-repl-type nbb) server-buffer)))
599+
600+
;; native cljs REPL
601+
(expect (buffer-local-value 'cider-repl-type client-buffer)
602+
:to-equal 'cljs)
603+
(expect (buffer-local-value 'cider-repl-cljs-upgrade-pending client-buffer)
604+
:to-equal nil)
605+
(expect (buffer-local-value 'cider-repl-init-function client-buffer)
606+
:to-be nil)
607+
(delete-process (get-buffer-process client-buffer)))))
605608
(it "for shadow project"
606609
(let* ((cider-shadow-default-options "a-shadow-alias")
607610
(server-process (nrepl-start-mock-server-process))
608-
(server-buffer (process-buffer server-process))
609-
(client-buffer (cider-connect-sibling-cljs
610-
'(:cljs-repl-type shadow) server-buffer)))
611+
(server-buffer (process-buffer server-process)))
612+
;; wait for the connection to be established
613+
(nrepl-tests-poll-until (local-variable-p 'nrepl-endpoint server-buffer) 5)
611614
;; starts as clj REPL and requires a form to switch over to cljs
612-
(expect (buffer-local-value 'cider-repl-type client-buffer)
613-
:to-equal 'cljs)
614-
(expect (buffer-local-value 'cider-repl-cljs-upgrade-pending client-buffer)
615-
:to-equal t)
616-
(expect (buffer-local-value 'cider-repl-init-function client-buffer)
617-
:not :to-be nil)
618-
(delete-process (get-buffer-process client-buffer))))
615+
(let ((client-buffer (cider-connect-sibling-cljs
616+
'(:cljs-repl-type shadow) server-buffer)))
617+
(expect (buffer-local-value 'cider-repl-type client-buffer)
618+
:to-equal 'cljs)
619+
(expect (buffer-local-value 'cider-repl-cljs-upgrade-pending client-buffer)
620+
:to-equal t)
621+
(expect (buffer-local-value 'cider-repl-init-function client-buffer)
622+
:not :to-be nil)
623+
(delete-process (get-buffer-process client-buffer)))))
619624
(it "for a custom cljs REPL type project"
620625
(cider-register-cljs-repl-type 'native-cljs)
621626
(let* ((server-process (nrepl-start-mock-server-process))
622-
(server-buffer (process-buffer server-process))
623-
(client-buffer (cider-connect-sibling-cljs
624-
'(:cljs-repl-type native-cljs)
625-
server-buffer)))
626-
(expect (buffer-local-value 'cider-repl-type client-buffer)
627-
:to-equal 'cljs)
628-
(expect (buffer-local-value 'cider-repl-cljs-upgrade-pending client-buffer)
629-
:to-equal nil)
630-
(delete-process (get-buffer-process client-buffer))))
627+
(server-buffer (process-buffer server-process)))
628+
;; wait for the connection to be established
629+
(nrepl-tests-poll-until (local-variable-p 'nrepl-endpoint server-buffer) 5)
630+
(let ((client-buffer (cider-connect-sibling-cljs
631+
'(:cljs-repl-type native-cljs)
632+
server-buffer)))
633+
(expect (buffer-local-value 'cider-repl-type client-buffer)
634+
:to-equal 'cljs)
635+
(expect (buffer-local-value 'cider-repl-cljs-upgrade-pending client-buffer)
636+
:to-equal nil)
637+
(delete-process (get-buffer-process client-buffer)))))
631638
(it "for a custom REPL type project that needs to switch to cljs"
632639
(cider-register-cljs-repl-type
633640
'not-cljs-initially "(form-to-switch-to-cljs-repl)")
634641
(let* ((server-process (nrepl-start-mock-server-process))
635-
(server-buffer (process-buffer server-process))
636-
(client-buffer (cider-connect-sibling-cljs
637-
'(:cljs-repl-type not-cljs-initially)
638-
server-buffer)))
639-
(expect (buffer-local-value 'cider-repl-type client-buffer)
640-
:to-equal 'cljs)
641-
(expect (buffer-local-value 'cider-repl-cljs-upgrade-pending client-buffer)
642-
:to-equal t)
643-
(expect (buffer-local-value 'cider-repl-init-function client-buffer)
644-
:not :to-be nil)
645-
(delete-process (get-buffer-process client-buffer))))))
642+
(server-buffer (process-buffer server-process)))
643+
;; wait for the connection to be established
644+
(nrepl-tests-poll-until (local-variable-p 'nrepl-endpoint server-buffer) 5)
645+
(let ((client-buffer (cider-connect-sibling-cljs
646+
'(:cljs-repl-type not-cljs-initially)
647+
server-buffer)))
648+
(expect (buffer-local-value 'cider-repl-type client-buffer)
649+
:to-equal 'cljs)
650+
(expect (buffer-local-value 'cider-repl-cljs-upgrade-pending client-buffer)
651+
:to-equal t)
652+
(expect (buffer-local-value 'cider-repl-init-function client-buffer)
653+
:not :to-be nil)
654+
(delete-process (get-buffer-process client-buffer)))))))
646655

647656
(provide 'cider-tests)
648657

test/nrepl-client-tests.el

+4-7
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,10 @@
152152
server-buffer))))
153153

154154
;; server up and running
155-
(nrepl-tests-sleep-until 2 (eq (process-status server-process) 'run))
156-
(expect (process-status server-process)
157-
:to-equal 'run)
155+
(nrepl-tests-poll-until (eq (process-status server-process) 'run) 2)
158156

159157
;; server has reported its endpoint
160-
(nrepl-tests-sleep-until 2 server-endpoint)
161-
(expect server-endpoint :not :to-be nil)
158+
(nrepl-tests-poll-until server-endpoint 2)
162159
(expect (plist-get (process-plist server-process) :cider--nrepl-server-ready)
163160
:to-equal t)
164161
(condition-case error-details
@@ -183,8 +180,8 @@
183180
(delete-process process-client)
184181

185182
;; server process has been signalled
186-
(nrepl-tests-sleep-until 4 (member (process-status server-process)
187-
'(exit signal)))
183+
(nrepl-tests-poll-until (member (process-status server-process)
184+
'(exit signal)) 4)
188185
(expect (let ((status (process-status server-process)))
189186
(if (eq system-type 'windows-nt)
190187
(eq status 'exit)

test/utils/nrepl-tests-utils.el

+13-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
;;; Code:
2727

28+
(require 'cl-lib)
2829
(require 'nrepl-client)
2930

3031
(defmacro nrepl-tests-log/init! (enable? name log-filename &optional clean?)
@@ -59,14 +60,18 @@ same file).
5960
`(defmacro ,log-symbol (fmt &rest rest)
6061
'()))))
6162

62-
(defmacro nrepl-tests-sleep-until (timeout-secs condition)
63-
"Sleep for up to TIMEOUT-SECS or until CONDITION becomes true. It wakes
64-
up every 0.2 seconds to check for CONDITION."
63+
(defmacro nrepl-tests-poll-until (condition timeout-secs)
64+
"Poll every 0.2 secs until CONDITION becomes true or error out if TIMEOUT-SECS elapses."
6565
(let* ((interval-secs 0.2)
6666
(count (truncate (/ timeout-secs interval-secs))))
6767
`(cl-loop repeat ,count
68-
until ,condition
69-
do (sleep-for ,interval-secs))))
68+
for condition = ,condition
69+
if condition
70+
return condition
71+
else
72+
do (sleep-for ,interval-secs)
73+
finally (error ":cider-tests-poll-until-errored :timed-out-after-secs %d :waiting-for %S"
74+
,timeout-secs (quote ,condition)))))
7075

7176
(defun nrepl-server-mock-invocation-string ()
7277
"Return a shell command that can be used by nrepl-start-srever-process to
@@ -101,15 +106,11 @@ calling process."
101106

102107
(defun nrepl-start-mock-server-process ()
103108
"Start and return the mock nrepl server process."
104-
(let* ((up? nil)
105-
(server-process (nrepl-start-server-process
109+
(let ((server-process (nrepl-start-server-process
106110
default-directory
107111
(nrepl-server-mock-invocation-string)
108-
(lambda (server-buffer)
109-
(setq up? t))))
110-
server-buffer (process-buffer server-process))
111-
;; server has reported its endpoint
112-
(nrepl-tests-sleep-until 2 up?)
112+
(lambda (_server-buffer)
113+
(message ":nrepl-mock-server-process-started...")))))
113114
server-process))
114115

115116
(provide 'nrepl-tests-utils)

0 commit comments

Comments
 (0)