From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 22 11:48:44 2022 Received: (at 53389) by debbugs.gnu.org; 22 Jan 2022 16:48:44 +0000 Received: from localhost ([127.0.0.1]:37769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nBJZD-0008Vd-Tp for submit@debbugs.gnu.org; Sat, 22 Jan 2022 11:48:44 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:56940) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nBJZB-0008VQ-EL for 53389@debbugs.gnu.org; Sat, 22 Jan 2022 11:48:42 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id F2A2E25A; Sat, 22 Jan 2022 17:48:34 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Mz5GYKnSM7m6; Sat, 22 Jan 2022 17:48:33 +0100 (CET) Received: from ribbon (91-160-117-201.subs.proxad.net [91.160.117.201]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 5538FF8; Sat, 22 Jan 2022 17:48:33 +0100 (CET) From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Maxime Devos Subject: Re: bug#53389: [PATCH 0/9] Replace some mocking with with-http-server*, avoid hardcoding ports, References: <6b1c1d98514b2547907a81a04c1241d9b865d6fa.camel@telenet.be> <20220120130849.292178-1-maximedevos@telenet.be> Date: Sat, 22 Jan 2022 17:48:32 +0100 In-Reply-To: <20220120130849.292178-1-maximedevos@telenet.be> (Maxime Devos's message of "Thu, 20 Jan 2022 13:08:41 +0000") Message-ID: <87lez7zpgf.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: / Authentication-Results: hera.aquilenet.fr; none X-Rspamd-Server: hera X-Rspamd-Queue-Id: F2A2E25A X-Spamd-Result: default: False [-0.10 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Score: 1.0 (+) 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: -0.0 (/) Hi Maxime, Maxime Devos skribis: > An incompatible change to with-http-server has been made: it now > also exits when the thunk exits. This change allows implementing > with-http-server*. It also keeps threads from lingering if the > thunk doesn't access all of RESPONSES+DATA. > > Usually, this change is fine, but it does not interact nicely with > monads in tests/challenge, so a variant with-http-server/lingering > preserving the old behaviour has been defined. > > * guix/tests/http.scm > (call-with-http-server): Extract most functionality to ... > (call-with-http-server*): ... this new procedure. Also stop the > server thread after 'thunk' returns instead of when the last response > has been sent unless requested not to. > (with-http-server/keep-lingering): New macro. > * tests/challenge.scm (call-mismatch-test): Use the 'keep-lingering' > variant of 'with-http-server'. [...] > #:export (with-http-server > + with-http-server/keep-lingering > + with-http-server* > call-with-http-server > + call-with-http-server* > %http-server-port > %local-url)) My first reaction was: have we gone overboard? :-) Since it=E2=80=99s an internal module and a test helper, I=E2=80=99m in fav= or of keeping it as simple as possible. Can we keep a single =E2=80=98with-http-server= =E2=80=99 form that would cover all cases? We can update existing tests to include the expected URL path (or a wildcard, if needed), instead of keeping several forms. We don=E2=80=99t n= eed to worry about backward compatibility at all. > + (unless keep-lingering? > + ;; exit the server thread > + (system-async-mark (lambda () (throw 'quit)) server)) When do we need =E2=80=98keep-lingering?=E2=80=99? So far, all uses of =E2=80=98with-http-server=E2=80=99 expected that the server would quit once= the last response has been sent. It would be nice if we could keep it that way. > + (apply values results))))) > + > + > +(define* (call-with-http-server responses+data thunk #:key (keep-lingeri= ng? #false)) > + "Call THUNK with an HTTP server running and returning RESPONSES+DATA > +on HTTP requests. Each element of RESPONSES+DATA must be a tuple contai= ning a > +response and a string, or an HTTP response code and a string. > + > +The argument RESPONSES+DATA is thunked. As such, RESPONSES+DATA can use > +%http-server-port. %http-server-port will be set to the port listened a= t. > +It will be set for the dynamic extent of THUNK and RESPONSES+DATA. > + > +The server will exit after the last response. When KEEP-LINGERING? is f= alse, > +the server will also exit after THUNK returns." Within tests, it would be nice if we could avoid using the =E2=80=98thunk= =E2=80=99 form and instead always use the declarative form (list of URL path/response code/response body). That should make the tests more concise and readable. Or are there new uses where the declarative form is insufficiently expressive? Thanks, Ludo=E2=80=99.