GNU bug report logs - #46668
[PATCH]: tests: do not hard code HTTP ports

Previous Next

Package: guix-patches;

Reported by: Maxime Devos <maximedevos <at> telenet.be>

Date: Sat, 20 Feb 2021 22:02:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 46668 in the body.
You can then email your comments to 46668 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#46668; Package guix-patches. (Sat, 20 Feb 2021 22:02:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Maxime Devos <maximedevos <at> telenet.be>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Sat, 20 Feb 2021 22:02:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Maxime Devos <maximedevos <at> telenet.be>
To: guix-patches <at> gnu.org
Subject: [PATCH]: tests: do not hard code HTTP ports
Date: Sat, 20 Feb 2021 23:00:30 +0100
[Message part 1 (text/plain, inline)]
Hi Guix,

I encountered a ‘Cannot listen to port: is bound’ error
or something like that when testing some changes to the
substituter.  I'm not sure yet what the cause is, but this
patch should eliminate some potential trouble, by not
hard-coding ports in tests that require a temporary http
server, and instead automatically assigning a free port.

Greetings,
Maxime
[0001-tests-do-not-hard-code-HTTP-ports.patch (text/x-patch, attachment)]
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#46668; Package guix-patches. (Mon, 01 Mar 2021 15:47:02 GMT) Full text and rfc822 format available.

Message #8 received at 46668 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Maxime Devos <maximedevos <at> telenet.be>
Cc: 46668 <at> debbugs.gnu.org
Subject: Re: bug#46668: [PATCH]: tests: do not hard code HTTP ports
Date: Mon, 01 Mar 2021 16:46:30 +0100
Hi Maxime,

Maxime Devos <maximedevos <at> telenet.be> skribis:

> From 6a5ea1f1a9155e23e46a38577adf74527ba50b2c Mon Sep 17 00:00:00 2001
> From: Maxime Devos <maximedevos <at> 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’.




Information forwarded to guix-patches <at> gnu.org:
bug#46668; Package guix-patches. (Mon, 01 Mar 2021 17:24:02 GMT) Full text and rfc822 format available.

Message #11 received at 46668 <at> debbugs.gnu.org (full text, mbox):

From: Maxime Devos <maximedevos <at> telenet.be>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 46668 <at> debbugs.gnu.org
Subject: Re: bug#46668: [PATCH]: tests: do not hard code HTTP ports
Date: Mon, 01 Mar 2021 18:23:00 +0100
[Message part 1 (text/plain, inline)]
On Mon, 2021-03-01 at 16:46 +0100, Ludovic Courtès wrote:
> [...]
> Maxime Devos <maximedevos <at> telenet.be> skribis: 
> > [...]
> 
> Nice!
> 
> Some comments below.
> 
> > +  #:use-module (ice-9 receive)
> Please use (srfi srfi-71) instead, or (srfi srfi-11).

Sure, will do.

You made some comments about ‘Hunks that shouldn't be here’ below.
I disagree.  As my explanation is exactly the same for almost all hunks,
I've numbered them and the explanations.

Explanations:

A.  (Hunk 2--12, i.e. all hunks except the first)
    In some tests, the port number is hardcoded.
    E.g., you'll see (test-equal "Some string http://localhost:9999" expression).
    Removing the hard-coding is the whole point of this patch.
B.  See later (hunk #1).
C.  See later (hunk #2).

Hunk #1.
> > -(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.

Explanation #B: If the hunk wasn't applied, then the first %local-url won't
work, as no web server is running yet (so we cannot yet know the port to
include in %local-url).  I've added a check to %local-url to throw an
exception when %http-server-port is 0 to prevent silently returning
"http://localhost:0/foo/bar", which is rather meaningless.

The "let" and "with-http-server" forms needed to be restructured,
and the %local-url of the first server needed to be saved with a "let",
to use the URL of the correct HTTP server.  There are two HTTP servers
in this test ...

Hunk #2.
> > -(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.

Explanation #A.  Also, explanation #C:

The "(parameterize ((%http-server-port 9999)) ...)"
form is required I think, as otherwise this test will try to connect to port 0,
which doesn't make much sense IMHO.  However, a quick test in Guile on Linux
shows:

> (socket AF_INET SOCK_STREAM 0)
$1 = #<input-output: socket 13>
> (connect $1 AF_INET INADDR_LOOPBACK 0)
ice-9/boot-9.scm:1669:16: In procedure raise-exception:
In procedure connect: Connection refused

It seems like connecting to port 0 results in ‘Connection refused’, but this
connecting to port 0 seems a rather obscure to me, so I would rather not rely
on this, though your opinion could vary.  (If we drop the parameterize,
then (%local-url) would need to be replaced with "http://localhost:0".)

-- And why hardcode the port in the first case?  Well, there isn't exactly
a procedure for asking the OS to reserve a port, but not bind to it.  Perhaps
something to figure out in a future patch ...

Hunk #3.
> > -(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.

Explanation #A.

Hunk #4.
> > -(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.

Explanation #A.

Hunk #5.
> > -(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.

Explanation #A.

Hunk #6.
> > -(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.

Explanation #A.

Hunk #7.
> > -(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.

Explanation #A.

Hunk #8.
> > -(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.

Explanation #A.

Hunk #9.
> > -(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.

Explanation #A.

Hunk #10.
> > -(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.

Explanation #A.

Hunk #11.
> > -(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.

Explanation #A.

Hunk #12.
> > -(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.

Explanation #A.

> Could you send an updated patch?

Is explanation #A clear, and does explanation #B make sense to you?
What do you think of explanation #C?

If you remove these hunks, you should see that the tests will fail
(make check TESTS=$tests).

Thanks,
Maxime.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#46668; Package guix-patches. (Mon, 01 Mar 2021 21:41:01 GMT) Full text and rfc822 format available.

Message #14 received at 46668 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Maxime Devos <maximedevos <at> telenet.be>
Cc: 46668 <at> debbugs.gnu.org
Subject: Re: bug#46668: [PATCH]: tests: do not hard code HTTP ports
Date: Mon, 01 Mar 2021 22:40:18 +0100
Hi,

Maxime Devos <maximedevos <at> telenet.be> skribis:

> You made some comments about ‘Hunks that shouldn't be here’ below.
> I disagree.  As my explanation is exactly the same for almost all hunks,
> I've numbered them and the explanations.
>
> Explanations:
>
> A.  (Hunk 2--12, i.e. all hunks except the first)
>     In some tests, the port number is hardcoded.
>     E.g., you'll see (test-equal "Some string http://localhost:9999" expression).
>     Removing the hard-coding is the whole point of this patch.
> B.  See later (hunk #1).
> C.  See later (hunk #2).

Oooh I see, my bad!  I thought ‘test-equal’ & co. were vanishing, when
in fact they were just moved down.  Your explanations make perfect
sense.

IWBN to keep the (test-xyz …) forms at the top level as much as possible
(it’s more convenient, especially when working from Geiser); when it’s
not possible, changes like you did are the right thing.

Thank you, and apologies for the confusion!

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#46668; Package guix-patches. (Tue, 02 Mar 2021 08:17:01 GMT) Full text and rfc822 format available.

Message #17 received at 46668 <at> debbugs.gnu.org (full text, mbox):

From: Maxime Devos <maximedevos <at> telenet.be>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 46668 <at> debbugs.gnu.org
Subject: Re: bug#46668: [PATCH]: tests: do not hard code HTTP ports
Date: Tue, 02 Mar 2021 09:15:57 +0100
[Message part 1 (text/plain, inline)]
On Mon, 2021-03-01 at 22:40 +0100, Ludovic Courtès wrote:
> [...]
> Thank you, and apologies for the confusion!
> 
> Ludo’.

No problem!  The revised patch that uses "let-values" instead of "receive"
is attached.

Maxime.
[0001-tests-do-not-hard-code-HTTP-ports.patch (text/x-patch, attachment)]
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#46668; Package guix-patches. (Tue, 02 Mar 2021 21:30:02 GMT) Full text and rfc822 format available.

Message #20 received at 46668 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Maxime Devos <maximedevos <at> telenet.be>
Cc: 46668 <at> debbugs.gnu.org
Subject: Re: bug#46668: [PATCH]: tests: do not hard code HTTP ports
Date: Tue, 02 Mar 2021 22:29:18 +0100
Hi,

Maxime Devos <maximedevos <at> telenet.be> skribis:

> From 933cb85de0f50c54190e7c60420bef5245a3f2ed Mon Sep 17 00:00:00 2001
> From: Maxime Devos <maximedevos <at> 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.

Minor comment but nothing blocking:

> +  (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))))))

It’s a tad confusing that the second ‘with-http-server’ is now nested;
it shouldn’t change the semantics though, so it’s okay.

Anyway, you’re welcome to push to ‘master’ if “make check” agrees.  :-)

Thanks again!

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#46668; Package guix-patches. (Tue, 02 Mar 2021 21:51:02 GMT) Full text and rfc822 format available.

Message #23 received at 46668 <at> debbugs.gnu.org (full text, mbox):

From: Maxime Devos <maximedevos <at> telenet.be>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 46668 <at> debbugs.gnu.org
Subject: Re: bug#46668: [PATCH]: tests: do not hard code HTTP ports
Date: Tue, 02 Mar 2021 22:49:55 +0100
[Message part 1 (text/plain, inline)]
On Tue, 2021-03-02 at 22:29 +0100, Ludovic Courtès wrote:
> 
> [...]
> It’s a tad confusing that the second ‘with-http-server’ is now nested;
> it shouldn’t change the semantics though, so it’s okay.
> 
> Anyway, you’re welcome to push to ‘master’ if “make check” agrees.  :-)

I do not have commit access, and I haven't applied for commit access either,
so you will have to push it yourself.  "make check" agreed when I wrote the
patch, though perhaps check it yourself just in case.

Greetings,
Maxime.
[signature.asc (application/pgp-signature, inline)]

Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Sat, 06 Mar 2021 10:25:01 GMT) Full text and rfc822 format available.

Notification sent to Maxime Devos <maximedevos <at> telenet.be>:
bug acknowledged by developer. (Sat, 06 Mar 2021 10:25:01 GMT) Full text and rfc822 format available.

Message #28 received at 46668-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Maxime Devos <maximedevos <at> telenet.be>
Cc: 46668-done <at> debbugs.gnu.org
Subject: Re: bug#46668: [PATCH]: tests: do not hard code HTTP ports
Date: Sat, 06 Mar 2021 11:23:53 +0100
Hi Maxime,

Maxime Devos <maximedevos <at> telenet.be> skribis:

> On Tue, 2021-03-02 at 22:29 +0100, Ludovic Courtès wrote:
>> 
>> [...]
>> It’s a tad confusing that the second ‘with-http-server’ is now nested;
>> it shouldn’t change the semantics though, so it’s okay.
>> 
>> Anyway, you’re welcome to push to ‘master’ if “make check” agrees.  :-)
>
> I do not have commit access, and I haven't applied for commit access either,
> so you will have to push it yourself.

Oops, my bad; applied now, thanks!

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 03 Apr 2021 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 24 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.