From: "Ludovic Courtès" <ludo@gnu.org>
To: Maxime Devos <maximedevos@telenet.be>
Cc: 46668@debbugs.gnu.org
Subject: [bug#46668] [PATCH]: tests: do not hard code HTTP ports
Date: Mon, 01 Mar 2021 16:46:30 +0100 [thread overview]
Message-ID: <87r1kyri5l.fsf@gnu.org> (raw)
In-Reply-To: <1728b9290c1b0e248b71c8b35623939853895a7f.camel@telenet.be> (Maxime Devos's message of "Sat, 20 Feb 2021 23:00:30 +0100")
Hi Maxime,
Maxime Devos <maximedevos@telenet.be> skribis:
> From 6a5ea1f1a9155e23e46a38577adf74527ba50b2c Mon Sep 17 00:00:00 2001
> From: Maxime Devos <maximedevos@telenet.be>
> 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 <http://bugs.gnu.org/25089>.
> - (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=? (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-url))))
> + #: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=? (call-with-input-file (derivation->output-path drv)
> + get-string-all)
> + text))))))
This hunk shouldn’t 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 (18 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-url))
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://localhost: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 (18 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://localhost: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://localhost: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’.
next prev parent reply other threads:[~2021-03-01 15:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-20 22:00 [bug#46668] [PATCH]: tests: do not hard code HTTP ports Maxime Devos
2021-03-01 15:46 ` Ludovic Courtès [this message]
2021-03-01 17:23 ` Maxime Devos
2021-03-01 21:40 ` Ludovic Courtès
2021-03-02 8:15 ` Maxime Devos
2021-03-02 21:29 ` Ludovic Courtès
2021-03-02 21:49 ` Maxime Devos
2021-03-06 10:23 ` bug#46668: " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r1kyri5l.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=46668@debbugs.gnu.org \
--cc=maximedevos@telenet.be \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.