diff mbox series

[bug#56563] gnu: tests: Fix guix-data-service test.

Message ID 20220714192137.23039-1-timotej.lazar@araneo.si
State Accepted
Headers show
Series [bug#56563] gnu: tests: Fix guix-data-service test. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Timotej Lazar July 14, 2022, 7:21 p.m. UTC
Since revision 32, guix-data-service starts immediately but returns an HTTP
error code until initialization is complete. Adjust the test accordingly, and
remove the increased startup time limit.

* gnu/services/guix.scm (guix-data-service): Use default #:pid-file-timeout.
* gnu/tests/guix.scm (guix-data-service): Retry the http-get test several
times to give the service time to initialize.
---
 gnu/services/guix.scm |  2 --
 gnu/tests/guix.scm    | 19 +++++++++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)

Comments

Munyoki Kilyungi July 14, 2022, 9:26 p.m. UTC | #1
Timotej Lazar <timotej.lazar@araneo.si> anaandika:

[...]
> +          ;; The service starts immediately but replies with status 500 until
> +          ;; initialization is complete, so keep trying for a while.
> +          (define* (try-http-get attempts)

Minor nitpick.  This function definition does not
take any optional or key-word arguments AFAICT, so
it should be a "define" instead :)

> +            (let ((status (let-values (((response text)
> +                                        (http-get #$(simple-format
> +                                                     #f "http://localhost:~A/healthcheck"
> +                                                     forwarded-port))))
> +                            (response-code response))))
> +              (if (or (= status 200) (<= attempts 1))
> +                  status
> +                  (begin (sleep 10) (try-http-get (- attempts 1))))))
> +
>            (test-equal "http-get"
>              200
> -            (let-values
> -                (((response text)
> -                  (http-get #$(simple-format
> -                               #f "http://localhost:~A/healthcheck" forwarded-port)
> -                            #:decode-body? #t)))
> -              (response-code response)))
> +            (try-http-get 10))
>  
>            (test-end))))
Timotej Lazar July 15, 2022, 5:52 a.m. UTC | #2
Munyoki Kilyungi <me@bonfacemunyoki.com> [2022-07-15 00:26:16+0300]:
> Timotej Lazar <timotej.lazar@araneo.si> anaandika:
>> +          (define* (try-http-get attempts)
>
> Minor nitpick.  This function definition does not
> take any optional or key-word arguments AFAICT, so
> it should be a "define" instead :)

It used to but then I changed my mind. :) Nice catch, I’ll send an
update. Thanks!
Munyoki Kilyungi July 15, 2022, 8:35 a.m. UTC | #3
Timotej Lazar <timotej.lazar@araneo.si> anaandika:

> Munyoki Kilyungi <me@bonfacemunyoki.com> [2022-07-15 00:26:16+0300]:
>> Timotej Lazar <timotej.lazar@araneo.si> anaandika:
>>> +          (define* (try-http-get attempts)
>>
>> Minor nitpick.  This function definition does not
>> take any optional or key-word arguments AFAICT, so
>> it should be a "define" instead :)
>
> It used to but then I changed my mind. :) Nice catch, I’ll send an
> update. Thanks!

Cool \m/\m/.
diff mbox series

Patch

diff --git a/gnu/services/guix.scm b/gnu/services/guix.scm
index 338e027245..dac1e5841a 100644
--- a/gnu/services/guix.scm
+++ b/gnu/services/guix.scm
@@ -652,8 +652,6 @@  (define (guix-data-service-shepherd-services config)
                 #:user #$user
                 #:group #$group
                 #:pid-file "/var/run/guix-data-service/pid"
-                ;; Allow time for migrations to run
-                #:pid-file-timeout 120
                 #:environment-variables
                 `(,(string-append
                     "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
diff --git a/gnu/tests/guix.scm b/gnu/tests/guix.scm
index a4c3e35e5d..ce62f74b60 100644
--- a/gnu/tests/guix.scm
+++ b/gnu/tests/guix.scm
@@ -222,14 +222,21 @@  (define marionette
                      ((pid) (number? pid))))))
              marionette))
 
+          ;; The service starts immediately but replies with status 500 until
+          ;; initialization is complete, so keep trying for a while.
+          (define* (try-http-get attempts)
+            (let ((status (let-values (((response text)
+                                        (http-get #$(simple-format
+                                                     #f "http://localhost:~A/healthcheck"
+                                                     forwarded-port))))
+                            (response-code response))))
+              (if (or (= status 200) (<= attempts 1))
+                  status
+                  (begin (sleep 10) (try-http-get (- attempts 1))))))
+
           (test-equal "http-get"
             200
-            (let-values
-                (((response text)
-                  (http-get #$(simple-format
-                               #f "http://localhost:~A/healthcheck" forwarded-port)
-                            #:decode-body? #t)))
-              (response-code response)))
+            (try-http-get 10))
 
           (test-end))))