From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id ECRnI8ZZ7GE3VAAAgWs5BA (envelope-from ) for ; Sat, 22 Jan 2022 20:23:50 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 4PMuIMZZ7GEDDAEAauVa8A (envelope-from ) for ; Sat, 22 Jan 2022 20:23:50 +0100 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 3A79E2DFBE for ; Sat, 22 Jan 2022 20:23:50 +0100 (CET) Received: from localhost ([::1]:54404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nBLzI-00081x-Sp for larch@yhetil.org; Sat, 22 Jan 2022 14:23:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBLxa-0005ae-Az for guix-patches@gnu.org; Sat, 22 Jan 2022 14:22:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:45035) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nBLxZ-00009o-PX for guix-patches@gnu.org; Sat, 22 Jan 2022 14:22:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nBLxZ-000470-Ms for guix-patches@gnu.org; Sat, 22 Jan 2022 14:22:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53389] [PATCH 0/9] Replace some mocking with with-http-server*, avoid hardcoding ports, Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 22 Jan 2022 19:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53389 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 53389@debbugs.gnu.org Received: via spool by 53389-submit@debbugs.gnu.org id=B53389.164287929615772 (code B ref 53389); Sat, 22 Jan 2022 19:22:01 +0000 Received: (at 53389) by debbugs.gnu.org; 22 Jan 2022 19:21:36 +0000 Received: from localhost ([127.0.0.1]:37938 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nBLx9-00046K-P3 for submit@debbugs.gnu.org; Sat, 22 Jan 2022 14:21:36 -0500 Received: from michel.telenet-ops.be ([195.130.137.88]:36380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nBLx7-00046B-AL for 53389@debbugs.gnu.org; Sat, 22 Jan 2022 14:21:34 -0500 Received: from ptr-bvsjgyhxw7psv60dyze.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:3c5f:2eff:feb0:ba5a]) by michel.telenet-ops.be with bizsmtp id lvMX2601G4UW6Th06vMXlE; Sat, 22 Jan 2022 20:21:31 +0100 Message-ID: From: Maxime Devos Date: Sat, 22 Jan 2022 20:21:26 +0100 In-Reply-To: <87lez7zpgf.fsf_-_@gnu.org> References: <6b1c1d98514b2547907a81a04c1241d9b865d6fa.camel@telenet.be> <20220120130849.292178-1-maximedevos@telenet.be> <87lez7zpgf.fsf_-_@gnu.org> Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-4KcSujT563+s6Em0NcGD" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r22; t=1642879291; bh=NqgQbPb4gvLFLfybi1aarPEo5tzacpsVzAD/Q6+JQmk=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=k4PXcajeGmQyuw+vo5W4PtE8mcI0P3wPw/eDlovlrvDhSulCIgcuJTBqn0Kl41Id3 TBHW3N1qu3QbyK7tV9K1+6YG3bN1caEtSxB3PFmvSajF3RISL8L1g3jWvYGjcxutxM d4NPRZxnPuvXbthLLk3AUIzRXRffyoIzyWAF/HMa2hutC2/v9PdnX/Z4Ier9CifSK7 9YpJbAIIpzHehXFEsY1zmvNA13KzAmcFIAUg/DmSQUtCo+0TtHhy85IjjEwFR44MbY DA2wtrdGgpe5X5Ul1oKL7B7d9E208Su8WqyTkcImG1LmabxwK5olyPNGRmCmuxtZ9K gUiwdpjm9necQ== 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 X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1642879430; 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: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: dkim-signature; bh=NqgQbPb4gvLFLfybi1aarPEo5tzacpsVzAD/Q6+JQmk=; b=B758CJ3qRI93jebI8oXy94aGEwX4AvFZp24BaCpbYwlRIy7N9lDfFUeNBLtmbLY4Lep30v XIyUEP118Z3XFIEoa5bJlMjsABtjMb+Y3yxCYtjFgqCoa9+htNY5w9L47voPekP0kXwDot h08+meCKskdDdF8bBByEe0i+SsJ3m4uSBdpcgwdA2BcvLvNL3B7vGKeyKGEptfVUWNhDiy yJwtJssPBgRb2CDVaCkJuao9qZuzqq1TILfRpbm11QF+JLRI3YrqrKW67xd8cCfYAJVupR 91TwM/6cSGGeO1VYYctgkR8AXsxLYj0hqXDs0VOoGtEUqJM7Kpc8t19KMDdDxA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1642879430; a=rsa-sha256; cv=none; b=nj3GMFjOOkSFZrQkWu4ZD54NsGQyiauJ7Z/h9QMtoTau79NGbC/V0vU3yCosGNg5eqeU3r TVw0ComNljmRa6u+byMNyxQeOV7z8gFBlBrP8DblaV0Li5OkhRLaReiuc9ciOK1j7D6Bn0 1CMdNB3UEs8megXyXWDtwcYfV46mcJe6I66GSQgzB/PCJ4yl2twr+ha6zbM+uVdwxCBMky rwDOrgHcZTYuMv3R5P2JIxg3sSoy5ex4HBGkNCtAQ2FYfWiN3Wk6VNUjXQCHQb2bFAFF4W HVlTz6se4z/kyjCIrRBx4emYVcl19RRwAadeDlg5F0KWRm3gacuPhZM56AjVKQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r22 header.b=k4PXcaje; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.73 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r22 header.b=k4PXcaje; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 3A79E2DFBE X-Spam-Score: -3.73 X-Migadu-Scanner: scn0.migadu.com X-TUID: QHqqp1FdB7ET --=-4KcSujT563+s6Em0NcGD Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s schreef op za 22-01-2022 om 17:48 [+0100]: > > +(define* (call-with-http-server responses+data thunk #:key (keep- > > lingering? #false)) > > +=C2=A0 "Call THUNK with an HTTP server running and returning > > RESPONSES+DATA > > +on HTTP requests.=C2=A0 Each element of RESPONSES+DATA must be a tuple > > containing a > > +response and a string, or an HTTP response code and a string. > > + > > +The argument RESPONSES+DATA is thunked.=C2=A0 As such, RESPONSES+DATA > > can use > > +%http-server-port.=C2=A0 %http-server-port will be set to the port > > listened at. > > +It will be set for the dynamic extent of THUNK and RESPONSES+DATA. > > + > > +The server will exit after the last response.=C2=A0 When KEEP- > > LINGERING? is false, > > +the server will also exit after THUNK returns." >=20 > Within tests, it would be nice if we could avoid using the =E2=80=98thunk= =E2=80=99 > form We can't unthunk 'thunk', otherwise the code querying the server will be run before the server starts, which isn't very useful. It's the same reasn why unthunking the 'thunk' argument of 'with-output-to-file' is not useful -- unless you only want to make a file empty I suppose. Did you mean 'responses+data'? For some context, consider tests/cpan.scm: - (with-http-server `((200 ,test-json) - (200 ,test-source) - (200 "{ \"distribution\" : \"Test-Script\" }")) - (parameterize ((%metacpan-base-url (%local-url)) - (current-http-proxy (%local-url))) + (with-http-server `(("/release/Foo-Bar" 200 ,(test-json)) + ("/Foo-Bar-0.1.tar.gz" 200 ,test-source) + ("/module/Test::Script?fields=3Ddistribution" + 200 "{ \"distribution\" : \"Test-Script\" }")) + (parameterize ((%metacpan-base-url (%local-url* "")) + (current-http-proxy #false)) (Side note: should parametrising current-http-proxy be moved into 'with-http-server', to avoid forgetting to do it in individual tests?) This 'with-http-server' is =E2=80=98self-referrent=E2=80=99: the responses = depend on the port that the HTTP server bound to -- (test-json) refers to http://localhost:THE-PORT/Foo-Bar-0.1.tar.gz. As such, the responses+data needs to be thunked, because this port is not known in advance. In principle, thunking can be avoided here by running two HTTP servers by nesting two with-http-server forms, but why make things more complicated by running multiple servers when a single one is sufficient? It can also be avoided by doing this proxy thing the original code did, but why complicate things with proxies when a regular server suffices? Also, tests don't really see that thunking happens unless they actually use the thunking to do make self-references, because all tests use with-http-server (*) (which does thunking automatically, not unlike 'package' records). So except for simplifying implementation details of call-with-http-server, I don't see how unthunking would make things nicer. (*) Unless they use with-http-server*. > and instead always use the declarative form (list of URL > path/response code/response body). Thunking and declarative forms don't appear mutually exclusive to me; the tests/cpan.scm example above uses a thunked declarative form. It would be nice to always specify the paths in the declarative form though, to make tests more precise, but there are a lot of tests to convert. > =C2=A0That should make the tests more concise and readable. The declarative form is still available and isn't going away. >=20 > Or are there new uses where the declarative form is insufficiently > expressive? tests/minetest.scm, see other mail. with-http-server is still declarative, so maybe you meant the functional with-http-server* instead? Greetings, Maxime --=-4KcSujT563+s6Em0NcGD Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYexZNhccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7p59AP99NGaQ1+gmQsJm94VjJTNruOyN 7e0HSIMSmP7kAf1FsgD8C6uZqByXzp1qAHiV4b2lJixqlIK6xFbOCVdnKelpOQI= =DKbF -----END PGP SIGNATURE----- --=-4KcSujT563+s6Em0NcGD--