From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 22 14:21:36 2022 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: Subject: Re: bug#53389: [PATCH 0/9] Replace some mocking with with-http-server*, avoid hardcoding ports, From: Maxime Devos To: Ludovic =?ISO-8859-1?Q?Court=E8s?= 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-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 53389 Cc: 53389@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-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--