From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.bugs Subject: bug#23708: [PATCH] package: =?UTF-8?Q?don=E2=80=99t?= hard code port number in test Date: Mon, 6 Jun 2016 21:53:33 +0200 Message-ID: <1465242813-2309-1-git-send-email-mina86@mina86.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1465242868 13353 80.91.229.3 (6 Jun 2016 19:54:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Jun 2016 19:54:28 +0000 (UTC) To: 23708@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 06 21:54:15 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bA0bH-0004rZ-1C for geb-bug-gnu-emacs@m.gmane.org; Mon, 06 Jun 2016 21:54:15 +0200 Original-Received: from localhost ([::1]:45351 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bA0bG-0007lr-3O for geb-bug-gnu-emacs@m.gmane.org; Mon, 06 Jun 2016 15:54:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bA0b6-0007j8-Dx for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2016 15:54:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bA0b4-000486-B0 for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2016 15:54:03 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:44737) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bA0b4-000482-7P for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2016 15:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bA0b3-00005A-Ve for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2016 15:54:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 06 Jun 2016 19:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 23708 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.1465242839300 (code B ref -1); Mon, 06 Jun 2016 19:54:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Jun 2016 19:53:59 +0000 Original-Received: from localhost ([127.0.0.1]:57074 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bA0b0-0008WS-OX for submit@debbugs.gnu.org; Mon, 06 Jun 2016 15:53:59 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:37917) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bA0az-0008WD-DL for submit@debbugs.gnu.org; Mon, 06 Jun 2016 15:53:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bA0as-00046G-Qa for submit@debbugs.gnu.org; Mon, 06 Jun 2016 15:53:52 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:39133) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bA0as-000467-Ns for submit@debbugs.gnu.org; Mon, 06 Jun 2016 15:53:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bA0aq-0007e9-4o for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2016 15:53:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bA0ak-00045e-U1 for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2016 15:53:47 -0400 Original-Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:36622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bA0ak-000454-JX for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2016 15:53:42 -0400 Original-Received: by mail-wm0-x22a.google.com with SMTP id n184so107695515wmn.1 for ; Mon, 06 Jun 2016 12:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=YWa9cuhTkPjaJz4Qmyk/XTG6M3zVTth5nYgC3ML9Cms=; b=hpSesSBtj2x/lEq3k91edni7pIpZTxDeXHsfbRySMhbDDwIAsICwrg1dl1OvvCMPGR zViOCjAIX2aUrKhqBIbRsTnbDPXrXPgOIKjIwLIOMlmSP0KWeGrTFdriVZAej8afIMbw MYk32rDS/Dl6+07wss5xoNIgn01kVPFtNQs0nxUcHZJY4VkGGy82S9Cp6e47+QDgOuKF rQqxOjYwLr+pAaSZ0ECa6+j9ZxcE6ym80l24GfsV5Q5CIJI405/mtVDr2XvzLInGH8Mg 8bJlRqRsBzwcXPO9CnT4uQHYIZvARe3ggEQoSVpN1MSX4N8q/ByzN2s2b8jKN9lg6HF6 d7nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version:content-transfer-encoding; bh=YWa9cuhTkPjaJz4Qmyk/XTG6M3zVTth5nYgC3ML9Cms=; b=hTJLzlXCpNJhzFFg7sdX9cJlxU6rHogbd/Y/c0cQ4eG3jcmCFFQYMBPqqio2TtIzrK pXZI65KQpNNxI9oE6wCvPn2cPc82wgCK4CUdKbGG7ZPRpep9qU/kcT/GKi81mtY6MA0k KWWf1u+epZ0jESIdpDFIPaQuhzM7+z4bLkFw+SrDbItSXPlmoskNMdAlYAwqvBEeHfeZ j0jt6sai5XB+tY7umuiaawQTItyynzawSBjcwPD3R7uGKdclOPGGVYMfnGRl5Al4oO6m kTI8ou1Kz/NNZnjg05FLYYMOvgY263adbgh8hMrIURC9LpnrErnSYYI4mlTg7QPKgD8f fWvQ== X-Gm-Message-State: ALyK8tJcpBdmxsJpLmbPM8F7/X+BbXjcy4Z9tbNt1uhXdlZAnTJG/NvLBp6m9Y11HhoHFqXs X-Received: by 10.28.30.209 with SMTP id e200mr419628wme.90.1465242820552; Mon, 06 Jun 2016 12:53:40 -0700 (PDT) Original-Received: from mpn.zrh.corp.google.com ([2620:0:105f:301:591a:9192:38e9:8b21]) by smtp.gmail.com with ESMTPSA id u4sm21790752wjz.4.2016.06.06.12.53.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jun 2016 12:53:38 -0700 (PDT) Original-Received: by mpn.zrh.corp.google.com (Postfix, from userid 126942) id A9AAE1E35D5; Mon, 6 Jun 2016 21:53:37 +0200 (CEST) X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:119180 Archived-At: 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