Be more diligent with processes used during testing

This commit is contained in:
Nathaniel Nicandro 2019-05-09 21:16:10 -05:00
parent db3bf0b681
commit b6d221c835
2 changed files with 40 additions and 37 deletions

View file

@ -639,8 +639,11 @@
(let ((jupyter-current-client
(jupyter-make-client manager 'jupyter-kernel-client)))
(jupyter-start-channels jupyter-current-client)
(jupyter-wait-until-startup jupyter-current-client)
(should (equal (jupyter-eval "1 + 1") "2")))
(unwind-protect
(progn
(jupyter-wait-until-startup jupyter-current-client)
(should (equal (jupyter-eval "1 + 1") "2")))
(jupyter-stop-channels jupyter-current-client)))
(jupyter-shutdown-kernel manager))))))
;;; Client
@ -1428,21 +1431,20 @@ last element being the newest element added to the history."
(ert-deftest jupyter-connect-repl ()
:tags '(repl)
(jupyter-test-with-python-repl client
(let ((client (jupyter-connect-repl
(jupyter-session-conn-info
(oref client session)))))
(let ((cclient (jupyter-connect-repl
(jupyter-session-conn-info
(oref client session)))))
(unwind-protect
(let ((msg (jupyter-wait-until-received :execute-result
(let ((jupyter-inhibit-handlers t))
(jupyter-send-execute-request client
(jupyter-send-execute-request cclient
:code "1 + 1")))))
(should msg)
(should (equal (jupyter-message-data msg :text/plain) "2")))
(cl-letf (((symbol-function 'yes-or-no-p)
(lambda (_prompt) t))
((symbol-function 'y-or-n-p)
(lambda (_prompt) t)))
(kill-buffer (oref client buffer)))))))
(with-current-buffer (oref cclient buffer)
(jupyter-stop-channels cclient)
(let ((kill-buffer-query-functions nil))
(kill-buffer)))))))
;;; `org-mode'

View file

@ -159,33 +159,34 @@ If the `current-buffer' is not a REPL, this is identical to
(declare (indent 4) (debug (functionp symbolp stringp symbolp &rest form)))
(let ((spec (make-symbol "spec"))
(saved (make-symbol "saved")))
`(let* ((,spec (progn (jupyter-error-if-no-kernelspec ,kernel)
(car (jupyter-find-kernelspecs ,kernel))))
(,saved (let ((saved (cdr (assoc (car ,spec) ,saved-sym))))
(if (and saved (slot-boundp saved 'manager)
(not (jupyter-kernel-alive-p (oref saved manager))))
;; If a kernel has died, e.g. being shutdown, remove
;; it.
(prog1 nil
(delq (assoc (car ,spec) ,saved-sym) ,saved-sym))
saved)))
(,client (if (and ,saved (not jupyter-test-with-new-client))
,saved
;; Want a fresh kernel, so shutdown the cached one
(when ,saved
(if (slot-boundp ,saved 'manager)
(jupyter-shutdown-kernel (oref ,saved manager))
(jupyter-send-shutdown-request ,saved))
(jupyter-stop-channels ,saved))
(let ((client (,client-fun (car ,spec))))
(prog1 client
(unless (or jupyter-test-with-new-client ,saved)
`(progn
;; If a kernel has died, e.g. being shutdown, remove it.
(cl-loop
for saved in (copy-sequence ,saved-sym)
for client = (cdr saved)
when (and client (slot-boundp client 'manager)
(not (jupyter-kernel-alive-p (oref client manager))))
do (jupyter-stop-channels client)
(cl-callf2 delq saved ,saved-sym))
(let* ((,spec (progn (jupyter-error-if-no-kernelspec ,kernel)
(car (jupyter-find-kernelspecs ,kernel))))
(,saved (cdr (assoc (car ,spec) ,saved-sym)))
(,client (if (and ,saved (not jupyter-test-with-new-client))
,saved
;; Want a fresh kernel, so shutdown the cached one
(when ,saved
(if (slot-boundp ,saved 'manager)
(jupyter-shutdown-kernel (oref ,saved manager))
(jupyter-send-shutdown-request ,saved))
(jupyter-stop-channels ,saved))
(let ((client (,client-fun (car ,spec))))
(prog1 client
(let ((el (cons (car ,spec) client)))
(push el ,saved-sym))))))))
;; See the note about increasing timeouts during CI testing at the top
;; of jupyter-test.el
(accept-process-output nil 0.5)
,@body)))
(push el ,saved-sym)))))))
;; See the note about increasing timeouts during CI testing at the top
;; of jupyter-test.el
(accept-process-output nil 1)
,@body))))
(defmacro jupyter-test-with-kernel-client (kernel client &rest body)
"Start a new KERNEL client, bind it to CLIENT, evaluate BODY.