From patchwork Sun Jan 31 18:52:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: M X-Patchwork-Id: 26792 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5455527BC1D; Sun, 31 Jan 2021 18:57:59 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 13A6627BC1E for ; Sun, 31 Jan 2021 18:57:58 +0000 (GMT) Received: from localhost ([::1]:39436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6Hv3-0004oO-2O for patchwork@mira.cbaines.net; Sun, 31 Jan 2021 13:57:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6HqL-0008Nn-3T for guix-patches@gnu.org; Sun, 31 Jan 2021 13:53:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:46476) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l6HqI-0001oJ-2g for guix-patches@gnu.org; Sun, 31 Jan 2021 13:53:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l6HqI-00032z-1e for guix-patches@gnu.org; Sun, 31 Jan 2021 13:53:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#46216] [PATCH] Remove duplication in tests/publish.scm Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 31 Jan 2021 18:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46216 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 46216@debbugs.gnu.org, maximedevos@telenet.be Received: via spool by 46216-submit@debbugs.gnu.org id=B46216.161211914311669 (code B ref 46216); Sun, 31 Jan 2021 18:53:02 +0000 Received: (at 46216) by debbugs.gnu.org; 31 Jan 2021 18:52:23 +0000 Received: from localhost ([127.0.0.1]:58022 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l6Hpe-000328-O4 for submit@debbugs.gnu.org; Sun, 31 Jan 2021 13:52:23 -0500 Received: from andre.telenet-ops.be ([195.130.132.53]:34412) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l6Hpc-00031y-9h for 46216@debbugs.gnu.org; Sun, 31 Jan 2021 13:52:21 -0500 Received: from ptr-bvsjgyjmffd7q9timvx.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by andre.telenet-ops.be with bizsmtp id PWsJ240050mfAB401WsJaB; Sun, 31 Jan 2021 19:52:18 +0100 Message-ID: <1aba271c99c375ff9a308f350c0bd0802ee49f3e.camel@telenet.be> From: Maxime Devos Date: Sun, 31 Jan 2021 19:52:18 +0100 In-Reply-To: References: User-Agent: Evolution 3.34.2 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1612119138; bh=05uplpnCaKARgwRZXznqY+i4rBJ0WuOxrx9tUIYKa1Q=; h=Subject:From:Reply-To:To:Date:In-Reply-To:References; b=T0u8mj7cCf5Ow7EO2S+15BnhMUfgClVyVVjcnK6ansWlrjnX+b6ifnqHk42kA5gOU EsZk/oDCkLGNBgmFvbR+SrpiS4VHo2Fnvx06s9tviHODglIB90Gj20NUUYajj0aFmY pLqT4eOtmwZhEr678jQVRbYvWXj2d+Wah+x/+5FOhdXVieif4rtH2DKLv3xf9Fmpj9 p68SVlfQ6iqodPgbx8+BotpJBB6oy3lYP7hWM9bPXZRDpYETZPo73mWOqztPYdAwnF 3j6EslZm4xgUP5fVVCTiXG7QQAZRJ9B7+zRalxPiEMFLo+BeC5Jqgn2VChQsH1h9cR hbtPtx7dAdw1A== 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: , Reply-To: 46216@debbugs.gnu.org, Maxime Devos Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Oops, I forgot to attach the patch. From de2a51437482c4a6aa812872f15804803650c128 Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Sun, 31 Jan 2021 19:48:14 +0100 Subject: [PATCH] tests: publish: lessen code duplication. * tests/publish.scm (spawn-guix-publish): introduce procedure, and adjust tests to use it instead of using an inline definition. --- tests/publish.scm | 82 +++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 49 deletions(-) diff --git a/tests/publish.scm b/tests/publish.scm index 52101876b5..7c90332bda 100644 --- a/tests/publish.scm +++ b/tests/publish.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2015 David Thompson ;;; Copyright © 2020 by Amar M. Singh ;;; Copyright © 2016, 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2021 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -92,11 +93,20 @@ (lambda () exp ...))))) -;; Run a local publishing server in a separate thread. -(with-separate-output-ports - (call-with-new-thread - (lambda () - (guix-publish "--port=6789" "-C0")))) ;attempt to avoid port collision +;; Run local publishing servers in a separate thread. +;; Attempt to avoid port collision by choosing ports +;; unlikely to be used in the wild (6789 and higher) +(define (spawn-guix-publish port . extra-arguments) + "Run a local publishing server in a separate thread. +The server will listen at PORT. EXTRA-ARGUMENTS are +passed as-is as extra command-line arguments. +The resulting thread is returned." + (with-separate-output-ports + (call-with-new-thread + (lambda () + (apply guix-publish (format #f "--port=~a" port) extra-arguments))))) + +(spawn-guix-publish 6789 "-C0") (define (wait-until-ready port) ;; Wait until the server is accepting connections. @@ -257,10 +267,7 @@ References: ~%" `(("StorePath" . ,%item) ("URL" . ,(string-append "nar/gzip/" (basename %item))) ("Compression" . "gzip")) - (let ((thread (with-separate-output-ports - (call-with-new-thread - (lambda () - (guix-publish "--port=6799" "-C5")))))) + (let ((thread (spawn-guix-publish 6799 "-C5"))) (wait-until-ready 6799) (let* ((url (string-append "http://localhost:6799/" (store-path-hash-part %item) ".narinfo")) @@ -277,10 +284,7 @@ References: ~%" `(("StorePath" . ,%item) ("URL" . ,(string-append "nar/lzip/" (basename %item))) ("Compression" . "lzip")) - (let ((thread (with-separate-output-ports - (call-with-new-thread - (lambda () - (guix-publish "--port=6790" "-Clzip")))))) + (let ((thread (spawn-guix-publish 6790 "-Clzip"))) (wait-until-ready 6790) (let* ((url (string-append "http://localhost:6790/" (store-path-hash-part %item) ".narinfo")) @@ -315,10 +319,7 @@ References: ~%" 200) (call-with-temporary-directory (lambda (cache) - (let ((thread (with-separate-output-ports - (call-with-new-thread - (lambda () - (guix-publish "--port=6793" "-Cgzip:2" "-Clzip:2")))))) + (let ((thread (spawn-guix-publish 6793 "-Cgzip:2" "-Clzip:2"))) (wait-until-ready 6793) (let* ((base "http://localhost:6793/") (part (store-path-hash-part %item)) @@ -339,11 +340,8 @@ References: ~%" ("Compression" . "none")) 200 404) - (let ((thread (with-separate-output-ports - (call-with-new-thread - (lambda () - (guix-publish "--port=6798" "-C0" - "--nar-path=///foo/bar//chbouib/")))))) + (let ((thread (spawn-guix-publish 6798 "-C0" + "--nar-path=///foo/bar//chbouib/"))) (wait-until-ready 6798) (let* ((base "http://localhost:6798/") (part (store-path-hash-part %item)) @@ -425,12 +423,9 @@ References: ~%" 404) ;nar/… (call-with-temporary-directory (lambda (cache) - (let ((thread (with-separate-output-ports - (call-with-new-thread - (lambda () - (guix-publish "--port=6797" "-C2" - (string-append "--cache=" cache) - "--cache-bypass-threshold=0")))))) + (let ((thread (spawn-guix-publish 6797 "-C2" + (string-append "--cache=" cache) + "--cache-bypass-threshold=0"))) (wait-until-ready 6797) (let* ((base "http://localhost:6797/") (part (store-path-hash-part %item)) @@ -480,12 +475,9 @@ References: ~%" '(200 200 404) (call-with-temporary-directory (lambda (cache) - (let ((thread (with-separate-output-ports - (call-with-new-thread - (lambda () - (guix-publish "--port=6794" "-Cgzip:2" "-Clzip:2" - (string-append "--cache=" cache) - "--cache-bypass-threshold=0")))))) + (let ((thread (spawn-guix-publish 6794 "-Cgzip:2" "-Clzip:2" + (string-append "--cache=" cache) + "--cache-bypass-threshold=0"))) (wait-until-ready 6794) (let* ((base "http://localhost:6794/") (part (store-path-hash-part %item)) @@ -588,11 +580,8 @@ References: ~%" 200 (call-with-temporary-directory (lambda (cache) - (let ((thread (with-separate-output-ports - (call-with-new-thread - (lambda () - (guix-publish "--port=6795" - (string-append "--cache=" cache))))))) + (let ((thread (spawn-guix-publish 6795 + (string-append "--cache=" cache)))) (wait-until-ready 6795) ;; Make sure that, even if ITEM disappears, we're still able to fetch @@ -615,11 +604,9 @@ References: ~%" 200 (call-with-temporary-directory (lambda (cache) - (let ((thread (with-separate-output-ports - (call-with-new-thread - (lambda () - (guix-publish "--port=6788" "-C" "gzip" - (string-append "--cache=" cache))))))) + (let ((thread (spawn-guix-publish 6788 "-C" "gzip" + "--port=6788" "-C" "gzip" + (string-append "--cache=" cache)))) (wait-until-ready 6788) (let* ((base "http://localhost:6788/") @@ -651,11 +638,8 @@ References: ~%" ;; for a non-existing file name. (call-with-temporary-directory (lambda (cache) - (let ((thread (with-separate-output-ports - (call-with-new-thread - (lambda () - (guix-publish "--port=6787" "-C" "gzip" - (string-append "--cache=" cache))))))) + (let ((thread (spawn-guix-publish 6787 "-C" "gzip" + (string-append "--cache=" cache)))) (wait-until-ready 6787) (let* ((base "http://localhost:6787/") -- 2.30.0