From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id OO7SELcMPWC/RQAA0tVLHw (envelope-from ) for ; Mon, 01 Mar 2021 15:48:07 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 8HWDDLcMPWBGZAAAbx9fmQ (envelope-from ) for ; Mon, 01 Mar 2021 15:48:07 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5281526754 for ; Mon, 1 Mar 2021 16:48:06 +0100 (CET) Received: from localhost ([::1]:44300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGkmD-0005Yi-BA for larch@yhetil.org; Mon, 01 Mar 2021 10:48:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGklC-0004wa-W0 for guix-patches@gnu.org; Mon, 01 Mar 2021 10:47:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:38941) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGklC-0000LB-OJ for guix-patches@gnu.org; Mon, 01 Mar 2021 10:47:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lGklC-0000hV-Mw for guix-patches@gnu.org; Mon, 01 Mar 2021 10:47:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#46668] [PATCH]: tests: do not hard code HTTP ports Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 01 Mar 2021 15:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46668 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxime Devos Cc: 46668@debbugs.gnu.org Received: via spool by 46668-submit@debbugs.gnu.org id=B46668.16146136031802 (code B ref 46668); Mon, 01 Mar 2021 15:47:02 +0000 Received: (at 46668) by debbugs.gnu.org; 1 Mar 2021 15:46:43 +0000 Received: from localhost ([127.0.0.1]:50486 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGkks-0000SS-Jd for submit@debbugs.gnu.org; Mon, 01 Mar 2021 10:46:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46986) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGkkq-0000N0-LD for 46668@debbugs.gnu.org; Mon, 01 Mar 2021 10:46:41 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47381) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGkkk-00006b-Cw; Mon, 01 Mar 2021 10:46:34 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=55314 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lGkkj-0001cu-1A; Mon, 01 Mar 2021 10:46:34 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <1728b9290c1b0e248b71c8b35623939853895a7f.camel@telenet.be> Date: Mon, 01 Mar 2021 16:46:30 +0100 In-Reply-To: <1728b9290c1b0e248b71c8b35623939853895a7f.camel@telenet.be> (Maxime Devos's message of "Sat, 20 Feb 2021 23:00:30 +0100") Message-ID: <87r1kyri5l.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1614613686; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=f+mAFtlwcIjB2blm4Y0AAy8QJzFOVuWz4w1NBQ1BCFY=; b=nwTa37++GwMhLh5d5maWSGLFTmOmKK1UhdcnZsHDRbWyHAVAhkmUkBzudJcx/Fow5AV4d/ ir6kvpnRMp2WFA/NCnoQu+/K2avK/bMWdEcus5zoMVT8ny6b2FDcH99e5mvxOnkb2lE9mx krwYb6EvhoYnBlBT0sgMCho9icbHJpxx6N/rj4tgDtC/0BDuTZRkEqOFw6UuC84JGiFkyL g83IoaFnwMtCYMXC1knnz41se2Cwfu5lIVq2rBWCnWCyXL+1dt6VjghdSkmYDmWgSI+Rcw YXkoN+qy/I5hgY6KzKxh/ijF/VZxFgYYoM1yeVHDS1zowAodd4pKeqcoGlIyFg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614613686; a=rsa-sha256; cv=none; b=A0dxB5GA3ojsJ4YFGNpGB7VEhG+yIZrL1x447GMqKPXdfnSG3qVswTArzMDmMBT5zw1q8g 4h930K4YWzxQKu8F+5hQRMewEbYYk5ymdXe3LMwt8cIG1jo8Ml8H+N7qC2bN76h/tvw3wD OwVVFIYwGFwkISrJeq71KhuFJ/bB7xoMOWxCPlhRaP3IKQDHnIf79RKKx2MeqEFeETBXFM H0Zb+b/jgcgWUglku8CrKVKHrHFyDivA0r7icQ9L5OC9xsrp+uWvT5cNidFwm155Ti/to5 cIyqjPLqruHbZRdJlF4E4WpKO9ykXq3GqOWSj5H0MthbcSwu381Z9E10e1n3nA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -2.87 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 5281526754 X-Spam-Score: -2.87 X-Migadu-Scanner: scn0.migadu.com X-TUID: /d647bl1gIV4 Hi Maxime, Maxime Devos skribis: > From 6a5ea1f1a9155e23e46a38577adf74527ba50b2c Mon Sep 17 00:00:00 2001 > From: Maxime Devos > Date: Sat, 20 Feb 2021 22:04:59 +0100 > Subject: [PATCH] tests: do not hard code HTTP ports > > Previously, test cases could fail if some process was listening > at a hard-coded port. This patch eliminates most of these potential > failures, by automatically assigning an unbound port. This should > allow for building multiple guix trees in parallel outside a build > container, though this is currently untested. > > The test "home-page: Connection refused" in tests/lint.scm still > hardcodes port 9999, however. > > * guix/tests/http.scm > (http-server-can-listen?): remove now unused procedure. > (%http-server-port): default to port 0, meaning the OS > will automatically choose a port. > (open-http-server-socket): remove the false statement claiming > this procedure is exported and also return the allocated port > number. > (%local-url): raise an error if the port is obviously unbound. > (call-with-http-server): set %http-server-port to the allocated > port while the thunk is called. > * tests/derivations.scm: adjust test cases to use automatically > assign a port. As there is no risk of a port conflict now, > do not make any tests conditional upon 'http-server-can-listen?' > anymore. > * tests/elpa.scm: likewise. > * tests/lint.scm: likewise, and add a TODO comment about a port > that is still hard-coded. > * tests/texlive.scm: likewise. Nice! Some comments below. > + #:use-module (ice-9 receive) Please use (srfi srfi-71) instead, or (srfi srfi-11). > -(unless (http-server-can-listen?) > - (test-skip 1)) > (test-assert "'download' built-in builder, check mode" > ;; Make sure rebuilding the 'builtin:download' derivation in check mode > ;; works. See . > - (let* ((text (random-text)) > - (drv (derivation %store "world" > - "builtin:download" '() > - #:env-vars `(("url" > - . ,(object->string (%local-url))= )) > - #:hash-algo 'sha256 > - #:hash (gcrypt:sha256 (string->utf8 text))))) > - (and (with-http-server `((200 ,text)) > - (build-derivations %store (list drv))) > - (with-http-server `((200 ,text)) > - (build-derivations %store (list drv) > - (build-mode check))) > - (string=3D? (call-with-input-file (derivation->output-path drv) > - get-string-all) > - text)))) > + (let* ((text (random-text))) > + (with-http-server `((200 ,text)) > + (let ((drv (derivation %store "world" > + "builtin:download" '() > + #:env-vars `(("url" > + . ,(object->string (%local-ur= l)))) > + #:hash-algo 'sha256 > + #:hash (gcrypt:sha256 (string->utf8 text)))= )) > + (and drv (build-derivations %store (list drv)) > + (with-http-server `((200 ,text)) > + (build-derivations %store (list drv) > + (build-mode check))) > + (string=3D? (call-with-input-file (derivation->output-path = drv) > + get-string-all) > + text)))))) This hunk shouldn=E2=80=99t be here. > -(test-equal "home-page: Connection refused" > - "URI http://localhost:9999/foo/bar unreachable: Connection refused" > - (let ((pkg (package > - (inherit (dummy-package "x")) > - (home-page (%local-url))))) > - (single-lint-warning-message > - (check-home-page pkg)))) > +(parameterize ((%http-server-port 9999)) > + ;; TODO skip this test if some process is currently listening at 9999 > + (test-equal "home-page: Connection refused" > + "URI http://localhost:9999/foo/bar unreachable: Connection refused" > + (let ((pkg (package > + (inherit (dummy-package "x")) > + (home-page (%local-url))))) > + (single-lint-warning-message > + (check-home-page pkg))))) Likewise. > -(test-equal "home-page: 200 but short length" > - "URI http://localhost:9999/foo/bar returned suspiciously small file (1= 8 bytes)" > - (with-http-server `((200 "This is too small.")) > +(with-http-server `((200 "This is too small.")) > + (test-equal "home-page: 200 but short length" > + (format #f "URI ~a returned suspiciously small file (18 bytes)" > + (%local-url)) Likewise. > -(test-equal "home-page: 404" > - "URI http://localhost:9999/foo/bar not reachable: 404 (\"Such is life\= ")" > - (with-http-server `((404 ,%long-string)) > +(with-http-server `((404 ,%long-string)) > + (test-equal "home-page: 404" > + (format #f "URI ~a not reachable: 404 (\"Such is life\")" (%local-ur= l)) Likewise. > -(test-equal "home-page: 301, invalid" > - "invalid permanent redirect from http://localhost:9999/foo/bar" > - (with-http-server `((301 ,%long-string)) > +(with-http-server `((301 ,%long-string)) > + (test-equal "home-page: 301, invalid" > + (format #f "invalid permanent redirect from ~a" (%local-url)) Likewise. > -(test-equal "home-page: 301 -> 200" > - "permanent redirect from http://localhost:10000/foo/bar to http://loca= lhost:9999/foo/bar" > - (with-http-server `((200 ,%long-string)) > - (let* ((initial-url (%local-url)) > - (redirect (build-response #:code 301 > - #:headers > - `((location > - . ,(string->uri initial-url))= )))) > - (parameterize ((%http-server-port (+ 1 (%http-server-port)))) > - (with-http-server `((,redirect "")) > +(with-http-server `((200 ,%long-string)) > + (let* ((initial-url (%local-url)) > + (redirect (build-response #:code 301 > + #:headers > + `((location > + . ,(string->uri initial-url)))))) Likewise. > -(test-equal "home-page: 301 -> 404" > - "URI http://localhost:10000/foo/bar not reachable: 404 (\"Such is life= \")" > - (with-http-server '((404 "booh!")) > - (let* ((initial-url (%local-url)) > - (redirect (build-response #:code 301 > - #:headers > - `((location > - . ,(string->uri initial-url))= )))) > - (parameterize ((%http-server-port (+ 1 (%http-server-port)))) > - (with-http-server `((,redirect "")) > +(with-http-server `((404 "booh!")) Likewise. > -(test-equal "source: 200 but short length" > - "URI http://localhost:9999/foo/bar returned suspiciously small file (1= 8 bytes)" > - (with-http-server '((200 "This is too small.")) > +(with-http-server '((200 "This is too small.")) > + (test-equal "source: 200 but short length" > + (format #f "URI ~a returned suspiciously small file (18 bytes)" > + (%local-url)) Likewise. > -(test-equal "source: 404" > - "URI http://localhost:9999/foo/bar not reachable: 404 (\"Such is life\= ")" > - (with-http-server `((404 ,%long-string)) > +(with-http-server `((404 ,%long-string)) > + (test-equal "source: 404" > + (format #f "URI ~a not reachable: 404 (\"Such is life\")" > + (%local-url)) Likewise. > -(test-equal "source: 301 -> 200" > - "permanent redirect from http://localhost:10000/foo/bar to http://loca= lhost:9999/foo/bar" > - (with-http-server `((200 ,%long-string)) > - (let* ((initial-url (%local-url)) > - (redirect (build-response #:code 301 > - #:headers > - `((location > - . ,(string->uri initial-url))= )))) > - (parameterize ((%http-server-port (+ 1 (%http-server-port)))) > - (with-http-server `((,redirect "")) > +(with-http-server `((200 ,%long-string)) Likewise. > -(test-equal "source, git-reference: 301 -> 200" > - "permanent redirect from http://localhost:10000/foo/bar to http://loca= lhost:9999/foo/bar" > - (with-http-server `((200 ,%long-string)) > - (let* ((initial-url (%local-url)) > - (redirect (build-response #:code 301 > - #:headers > - `((location > - . ,(string->uri initial-url))= )))) > - (parameterize ((%http-server-port (+ 1 (%http-server-port)))) > - (with-http-server `((,redirect "")) > +(with-http-server `((200 ,%long-string)) Likewise. > -(test-equal "source: 301 -> 404" > - "URI http://localhost:10000/foo/bar not reachable: 404 (\"Such is life= \")" > - (with-http-server '((404 "booh!")) > - (let* ((initial-url (%local-url)) > - (redirect (build-response #:code 301 > - #:headers > - `((location > - . ,(string->uri initial-url))= )))) > - (parameterize ((%http-server-port (+ 1 (%http-server-port)))) > - (with-http-server `((,redirect "")) > +(with-http-server '((404 "booh!")) Likewise. Could you send an updated patch? Thanks! Ludo=E2=80=99.