GNU bug report logs -
#23708
[PATCH] package: don’t hard code port number in test
Previous Next
Reported by: Michal Nazarewicz <mina86 <at> mina86.com>
Date: Mon, 6 Jun 2016 19:54:01 UTC
Severity: minor
Tags: patch
Fixed in version 26.1
Done: Glenn Morris <rgm <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#23708: [PATCH] package: don’t hard code port number in test
which was filed against the emacs package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 23708 <at> debbugs.gnu.org.
--
23708: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23708
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Version: 25.2
Thanks; I installed something similar.
[Message part 3 (message/rfc822, inline)]
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
This bug report was last modified 8 years and 221 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.