]> git.eshelyaron.com Git - emacs.git/commitdiff
* test/automated/package-test.el: Test async functionality
authorArtur Malabarba <bruce.connor.am@gmail.com>
Sun, 12 Apr 2015 00:10:35 +0000 (01:10 +0100)
committerArtur Malabarba <bruce.connor.am@gmail.com>
Sun, 12 Apr 2015 00:12:33 +0000 (01:12 +0100)
(package-test-update-archives-async): New test

test/automated/data/package/package-test-server.py [new file with mode: 0644]
test/automated/package-test.el

diff --git a/test/automated/data/package/package-test-server.py b/test/automated/data/package/package-test-server.py
new file mode 100644 (file)
index 0000000..35ca820
--- /dev/null
@@ -0,0 +1,21 @@
+import sys
+import BaseHTTPServer
+from SimpleHTTPServer import SimpleHTTPRequestHandler
+
+
+HandlerClass = SimpleHTTPRequestHandler
+ServerClass  = BaseHTTPServer.HTTPServer
+Protocol     = "HTTP/1.0"
+
+if sys.argv[1:]:
+    port = int(sys.argv[1])
+else:
+    port = 8000
+    server_address = ('127.0.0.1', port)
+
+HandlerClass.protocol_version = Protocol
+httpd = ServerClass(server_address, HandlerClass)
+
+sa = httpd.socket.getsockname()
+print "Serving HTTP on", sa[0], "port", sa[1], "..."
+httpd.serve_forever()
index 5fae216ef7d0e082300961281874ab754c81e8ca..b343ed7285d27804f230ccaa4a5e3c5cdfac729a 100644 (file)
 (cl-defmacro with-package-test ((&optional &key file
                                            basedir
                                            install
+                                           location
                                            update-news
                                            upload-base)
                                 &rest body)
           (process-environment (cons (format "HOME=%s" package-test-user-dir)
                                      process-environment))
           (package-user-dir package-test-user-dir)
-          (package-archives `(("gnu" . ,package-test-data-dir)))
+          (package-archives `(("gnu" . ,(or ,location package-test-data-dir))))
           (default-directory package-test-file-dir)
           abbreviated-home-dir
           package--initialized
@@ -336,6 +337,33 @@ Must called from within a `tar-mode' buffer."
         (package-menu-refresh)
         (should (package-installed-p 'simple-single '(1 4)))))))
 
+(ert-deftest package-test-update-archives-async ()
+  "Test updating package archives asynchronously."
+  (skip-unless (executable-find "python2"))
+  (with-package-test (:basedir
+                      package-test-data-dir
+                      :location "http://0.0.0.0:8000/")
+    (let* ((package-menu-async t)
+           (process (start-process
+                     "package-server" "package-server-buffer"
+                     (executable-find "python2")
+                     (expand-file-name "package-test-server.py"))))
+      (unwind-protect
+          (progn
+            (list-packages)
+            (should package--downloads-in-progress)
+            (should mode-line-process)
+            (should-not (string= (format-mode-line mode-line-process) ""))
+            (should-not
+             (with-timeout (10 'timeout)
+               (while package--downloads-in-progress
+                 (accept-process-output nil 1))
+               nil))
+            (goto-char (point-min))
+            (should
+             (search-forward-regexp "^ +simple-single" nil t)))
+        (kill-process process)))))
+
 (ert-deftest package-test-describe-package ()
   "Test displaying help for a package."