diff --git a/.travis.yml b/.travis.yml index 3f6e92f..82454d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ sudo: required dist: trusty language: nix +addons: + apt: + packages: + - openssh-server matrix: # Report build failure/success before allowed failures complete fast_finish: true @@ -9,8 +13,8 @@ matrix: - env: EMACS_CI=emacs-snapshot env: - EMACS_CI=emacs-26-1 - - EMACS_CI=emacs-26-3 - - EMACS_CI=emacs-snapshot + # - EMACS_CI=emacs-26-3 + # - EMACS_CI=emacs-snapshot install: # Install Emacs - bash <(curl https://raw.githubusercontent.com/purcell/nix-emacs-ci/master/travis-install) @@ -37,6 +41,10 @@ before_script: script: - export PATH=$HOME/.cask/bin:$PATH - cd $TRAVIS_BUILD_DIR + # Ensure ssh does not prompt for anything + - ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa + - cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys + - ssh -o StrictHostKeyChecking=no localhost exit - make dev - make compile - - make test + - make test TAGS=ssh diff --git a/test/jupyter-test.el b/test/jupyter-test.el index eb3585d..729febd 100644 --- a/test/jupyter-test.el +++ b/test/jupyter-test.el @@ -771,6 +771,40 @@ (delete-file file))) (should-not (memq fun kill-emacs-hook)))) +;; TODO: Docker test +(ert-deftest jupyter-tunnel-connection () + :tags '(client ssh) + (jupyter-test-with-kernel "python" kernel + (with-current-buffer (process-buffer (oref kernel process)) + (goto-char (point-min)) + (re-search-forward "Connection file: \\(.+\\)\n") + ;; Ensure this is required since TRAMP will fail without it + ;; on Travis. + (require 'files-x) + (let* ((method (cdr (assoc "ssh" tramp-methods))) + (conn-file (match-string 1)) + (conn-info (jupyter-read-plist conn-file)) + (ssh-conn-file (concat "/ssh:localhost:" conn-file)) + (ssh-conn-info (jupyter-tunnel-connection ssh-conn-file))) + ;; FIXME: The IP in conn-file is already 127.0.0.1 + (should (equal (plist-get ssh-conn-info :ip) "127.0.0.1")) + (cl-loop for port in '(:hb_port + :control_port + :shell_port + :iopub_port + :stdin_port) + do (should-not + (equal (plist-get conn-info port) + (plist-get ssh-conn-info port)))) + ;; Can we talk to the kernel + (let* ((manager (jupyter-kernel-process-manager + :kernel kernel)) + (jupyter-current-client + (jupyter-make-client manager 'jupyter-kernel-client))) + (jupyter-start-channels jupyter-current-client) + (should (equal "2" (jupyter-eval "1 + 1"))) + (jupyter-stop-channels jupyter-current-client)))))) + (ert-deftest jupyter-client-channels () :tags '(client channels) (ert-info ("Starting/stopping channels") diff --git a/test/test-helper.el b/test/test-helper.el index efc2f7f..ff28260 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -234,18 +234,29 @@ If the `current-buffer' is not a REPL, this is identical to (accept-process-output nil 1) ,@body)))) +(defmacro jupyter-test-with-kernel (kernel-name kernel &rest body) + "Start a new kernel with name KERNEL-NAME, bind it to KERNEL, evaluate BODY. +KERNEL will be a `jupyter-command-kernel'." + (declare (indent 2)) + `(let ((,kernel (jupyter-command-kernel + :spec (jupyter-guess-kernelspec ,kernel-name)))) + (jupyter-start-kernel ,kernel) + (unwind-protect + (progn ,@body) + (jupyter-kill-kernel ,kernel)))) + (defmacro jupyter-test-with-kernel-client (kernel client &rest body) "Start a new KERNEL client, bind it to CLIENT, evaluate BODY. This only starts a single global client unless the variable `jupyter-test-with-new-client' is non-nil." (declare (indent 2) (debug (stringp symbolp &rest form))) `(jupyter-test-with-client-cache - (lambda (name) (cadr (jupyter-start-new-kernel name))) - jupyter-test-global-clients ,kernel ,client - (unwind-protect - (progn ,@body) - (when jupyter-test-with-new-client - (jupyter-shutdown-kernel (oref client manager)))))) + (lambda (name) (cadr (jupyter-start-new-kernel name))) + jupyter-test-global-clients ,kernel ,client + (unwind-protect + (progn ,@body) + (when jupyter-test-with-new-client + (jupyter-shutdown-kernel (oref client manager)))))) (defmacro jupyter-test-with-python-client (client &rest body) "Start a new Python kernel, bind it to CLIENT, evaluate BODY."