unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michal Nazarewicz <mina86@mina86.com>
To: 23708@debbugs.gnu.org
Subject: bug#23708: [PATCH] package: don’t hard code port number in test
Date: Mon,  6 Jun 2016 21:53:33 +0200	[thread overview]
Message-ID: <1465242813-2309-1-git-send-email-mina86@mina86.com> (raw)

Hard coding port 8000 in package-tests.el causes the test to fail if
something is already listening on that port.  Change code so it uses
any available port.

* tests/lisp/emacs-lisp/package-tests.el
  (package-test-update-archives-async): Do not hard code port number
  and instead parse it from server’s standard output.

* tests/lisp/emacs-lisp/package-resources/package-test-server.py:
  Do not hard code port number.  Use any available one instead.
---
 .../package-resources/package-test-server.py       | 15 ++----
 test/lisp/emacs-lisp/package-tests.el              | 54 ++++++++++++----------
 2 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/test/lisp/emacs-lisp/package-resources/package-test-server.py b/test/lisp/emacs-lisp/package-resources/package-test-server.py
index 35ca820..78e40b3 100644
--- a/test/lisp/emacs-lisp/package-resources/package-test-server.py
+++ b/test/lisp/emacs-lisp/package-resources/package-test-server.py
@@ -1,21 +1,16 @@
-import sys
+import os
 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)
+os.chdir(os.path.dirname(__file__))
 
 HandlerClass.protocol_version = Protocol
-httpd = ServerClass(server_address, HandlerClass)
+httpd = ServerClass(('127.0.0.1', 0), HandlerClass)
 
-sa = httpd.socket.getsockname()
-print "Serving HTTP on", sa[0], "port", sa[1], "..."
+# This printed line is parsed by test code, don't change its format.
+print "Serving on http://%s:%s/" % httpd.socket.getsockname()
 httpd.serve_forever()
diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el
index c7a5cc7..4ffb173 100644
--- a/test/lisp/emacs-lisp/package-tests.el
+++ b/test/lisp/emacs-lisp/package-tests.el
@@ -372,31 +372,35 @@ package-test-desc-version-string
   (skip-unless (executable-find "python2"))
   ;; For some reason this test doesn't work reliably on hydra.nixos.org.
   (skip-unless (not (getenv "NIX_STORE")))
-  (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
-             (with-timeout (10 'timeout)
-               (while package--downloads-in-progress
-                 (accept-process-output nil 1))
-               nil))
-            ;; If the server process died, there's some non-Emacs problem.
-            ;; Eg maybe the port was already in use.
-            (skip-unless (process-live-p process))
-            (goto-char (point-min))
-            (should
-             (search-forward-regexp "^ +simple-single" nil t)))
-        (if (process-live-p process) (kill-process process))))))
+
+  (with-temp-buffer
+    (cd package-test-data-dir)
+    (let ((package-menu-async t)
+          (process (start-process "package-server" (current-buffer)
+                                  (executable-find "python2")
+                                  (expand-file-name "package-test-server.py"))))
+      ;; Killing temp buffer will kill the process.
+      (set-process-query-on-exit-flag process nil)
+
+      (with-package-test
+          (:location (with-timeout (5 (should-not 'timeout))
+                       (while (and (goto-char (point-min))
+                                   (not (re-search-forward
+                                         "^Serving on \\(http://.*/\\)" nil t)))
+                         (accept-process-output process 1))
+                       (match-string 1)))
+        (list-packages)
+        (should package--downloads-in-progress)
+        (should mode-line-process)
+        (should-not (with-timeout (10 'timeout)
+                      (while package--downloads-in-progress
+                        (accept-process-output nil 1))
+                      nil))
+        ;; If the server process died, there's some non-Emacs problem.
+        ;; Eg maybe the port was already in use.
+        (skip-unless (process-live-p process))
+        (goto-char (point-min))
+        (should (search-forward-regexp "^ +simple-single" nil t))))))
 
 (ert-deftest package-test-describe-package ()
   "Test displaying help for a package."
-- 
2.8.0.rc3.226.g39d4020






             reply	other threads:[~2016-06-06 19:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-06 19:53 Michal Nazarewicz [this message]
2016-06-08  1:26 ` bug#23708: [PATCH] package: don’t hard code port number in test Glenn Morris
     [not found] ` <handler.23708.D23708.146534919527877.notifdone@debbugs.gnu.org>
2016-06-08 12:34   ` bug#23708: closed ( bug#23708: [PATCH] package: don’t hard code port number in test) Michal Nazarewicz
2016-06-08 16:02     ` Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1465242813-2309-1-git-send-email-mina86@mina86.com \
    --to=mina86@mina86.com \
    --cc=23708@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).