unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#23708: [PATCH] package: don’t hard code port number in test
@ 2016-06-06 19:53 Michal Nazarewicz
  2016-06-08  1:26 ` Glenn Morris
       [not found] ` <handler.23708.D23708.146534919527877.notifdone@debbugs.gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Michal Nazarewicz @ 2016-06-06 19:53 UTC (permalink / raw)
  To: 23708

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






^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#23708: [PATCH] package: don’t hard code port number in test
  2016-06-06 19:53 bug#23708: [PATCH] package: don’t hard code port number in test Michal Nazarewicz
@ 2016-06-08  1:26 ` Glenn Morris
       [not found] ` <handler.23708.D23708.146534919527877.notifdone@debbugs.gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Glenn Morris @ 2016-06-08  1:26 UTC (permalink / raw)
  To: 23708-done

Version: 25.2

Thanks; I installed something similar.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#23708: closed ( bug#23708: [PATCH] package: don’t hard code port number in test)
       [not found] ` <handler.23708.D23708.146534919527877.notifdone@debbugs.gnu.org>
@ 2016-06-08 12:34   ` Michal Nazarewicz
  2016-06-08 16:02     ` Glenn Morris
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Nazarewicz @ 2016-06-08 12:34 UTC (permalink / raw)
  To: 23708

Glenn Morris <rgm@gnu.org> wrote:
> Thanks; I installed something similar.

Note that currently argument parsing in package-test-server.py is
dysfunctional (passing an argument causes server_address to never be
set) so while my patch would fix that (by removing that unused feature).

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#23708: closed ( bug#23708: [PATCH] package: don’t hard code port number in test)
  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
  0 siblings, 0 replies; 4+ messages in thread
From: Glenn Morris @ 2016-06-08 16:02 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: 23708

Michal Nazarewicz wrote:

> Note that currently argument parsing in package-test-server.py is
> dysfunctional (passing an argument causes server_address to never be
> set) so while my patch would fix that (by removing that unused feature).

(Sorry, I did not notice that you have write access.) Feel free to fix
that if it bothers you.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-08 16:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-06 19:53 bug#23708: [PATCH] package: don’t hard code port number in test Michal Nazarewicz
2016-06-08  1:26 ` 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

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).