diff options
| author | Giacomo Leidi <goodoldpaul@autistici.org> | 2025-08-24 16:59:44 +0200 |
|---|---|---|
| committer | Maxim Cournoyer <maxim@guixotic.coop> | 2025-08-25 13:04:36 +0900 |
| commit | d6200cefcc18e55df07fc0e5dabbb4f5f7de7bb4 (patch) | |
| tree | b030e7ba9db5a46cfc2c72bfe4cddc9ffb1828ba /gnu/tests/docker.scm | |
| parent | 0aef9716b6402c7ff116273d2a74298708030d1b (diff) | |
tests: oci-container: Set explicit timeouts.
* gnu/tests/docker.scm: Simplify %test-oci-container test case and add
explicit timeouts to tests outcomes.
Change-Id: I75868479dcce031f3edc98064b1ebcf975f598f5
Signed-off-by: Maxim Cournoyer <maxim@guixotic.coop>
Diffstat (limited to 'gnu/tests/docker.scm')
| -rw-r--r-- | gnu/tests/docker.scm | 99 |
1 files changed, 41 insertions, 58 deletions
diff --git a/gnu/tests/docker.scm b/gnu/tests/docker.scm index 8952daab2f5..9fee3905f0e 100644 --- a/gnu/tests/docker.scm +++ b/gnu/tests/docker.scm | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org> | 2 | ;;; Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org> |
| 3 | ;;; Copyright © 2019-2023 Ludovic Courtès <ludo@gnu.org> | 3 | ;;; Copyright © 2019-2023 Ludovic Courtès <ludo@gnu.org> |
| 4 | ;;; Copyright © 2024 Giacomo Leidi <goodoldpaul@autistici.org> | 4 | ;;; Copyright © 2024, 2025 Giacomo Leidi <goodoldpaul@autistici.org> |
| 5 | ;;; | 5 | ;;; |
| 6 | ;;; This file is part of GNU Guix. | 6 | ;;; This file is part of GNU Guix. |
| 7 | ;;; | 7 | ;;; |
| @@ -414,71 +414,54 @@ docker-image} inside Docker.") | |||
| 414 | (test-runner-current (system-test-runner #$output)) | 414 | (test-runner-current (system-test-runner #$output)) |
| 415 | (test-begin "oci-container") | 415 | (test-begin "oci-container") |
| 416 | 416 | ||
| 417 | (test-assert "containerd service running" | 417 | (wait-for-file "/run/containerd/containerd.pid" marionette) |
| 418 | (marionette-eval | ||
| 419 | '(begin | ||
| 420 | (use-modules (gnu services herd)) | ||
| 421 | (match (start-service 'containerd) | ||
| 422 | (#f #f) | ||
| 423 | (('service response-parts ...) | ||
| 424 | (match (assq-ref response-parts 'running) | ||
| 425 | ((pid) pid))))) | ||
| 426 | marionette)) | ||
| 427 | |||
| 428 | (test-assert "containerd PID file present" | ||
| 429 | (wait-for-file "/run/containerd/containerd.pid" marionette)) | ||
| 430 | |||
| 431 | (test-assert "dockerd running" | ||
| 432 | (marionette-eval | ||
| 433 | '(begin | ||
| 434 | (use-modules (gnu services herd)) | ||
| 435 | (match (start-service 'dockerd) | ||
| 436 | (#f #f) | ||
| 437 | (('service response-parts ...) | ||
| 438 | (match (assq-ref response-parts 'running) | ||
| 439 | ((pid) pid))))) | ||
| 440 | marionette)) | ||
| 441 | |||
| 442 | (sleep 10) ; let service start | ||
| 443 | 418 | ||
| 444 | (test-assert "docker-guile running" | 419 | (test-assert "docker-guile running" |
| 445 | (marionette-eval | 420 | (marionette-eval |
| 446 | '(begin | 421 | '(begin |
| 447 | (use-modules (gnu services herd)) | 422 | (use-modules (gnu services herd)) |
| 448 | (match (start-service 'docker-guile) | 423 | (wait-for-service 'docker-guile #:timeout 120) |
| 449 | (#f #f) | 424 | #t) |
| 450 | (('service response-parts ...) | ||
| 451 | (match (assq-ref response-parts 'running) | ||
| 452 | ((pid) pid))))) | ||
| 453 | marionette)) | 425 | marionette)) |
| 454 | 426 | ||
| 455 | (test-equal "passing host environment variables and volumes" | 427 | (test-assert "passing host environment variables and volumes" |
| 456 | '("value" "hello") | 428 | (begin |
| 457 | (marionette-eval | 429 | (define (run-test) |
| 458 | `(begin | 430 | (marionette-eval |
| 459 | (use-modules (ice-9 popen) | 431 | `(begin |
| 460 | (ice-9 rdelim)) | 432 | (use-modules (ice-9 popen) |
| 461 | 433 | (ice-9 rdelim)) | |
| 462 | (define slurp | 434 | |
| 463 | (lambda args | 435 | (define slurp |
| 464 | (let* ((port (apply open-pipe* OPEN_READ args)) | 436 | (lambda args |
| 465 | (output (let ((line (read-line port))) | 437 | (let* ((port (apply open-pipe* OPEN_READ args)) |
| 466 | (if (eof-object? line) | 438 | (output (let ((line (read-line port))) |
| 467 | "" | 439 | (if (eof-object? line) |
| 468 | line))) | 440 | "" |
| 469 | (status (close-pipe port))) | 441 | line))) |
| 470 | output))) | 442 | (status (close-pipe port))) |
| 471 | (let* ((response1 (slurp | 443 | output))) |
| 472 | ,(string-append #$docker-cli "/bin/docker") | 444 | (let* ((response1 (slurp |
| 473 | "exec" "docker-guile" | 445 | ,(string-append #$docker-cli "/bin/docker") |
| 474 | "/bin/guile" "-c" "(display (getenv \"VARIABLE\"))")) | 446 | "exec" "docker-guile" |
| 475 | (response2 (slurp | 447 | "/bin/guile" "-c" "(display (getenv \"VARIABLE\"))")) |
| 476 | ,(string-append #$docker-cli "/bin/docker") | 448 | (response2 (slurp |
| 477 | "exec" "docker-guile" | 449 | ,(string-append #$docker-cli "/bin/docker") |
| 478 | "/bin/guile" "-c" "(begin (use-modules (ice-9 popen) (ice-9 rdelim)) | 450 | "exec" "docker-guile" |
| 451 | "/bin/guile" "-c" "(begin (use-modules (ice-9 popen) (ice-9 rdelim)) | ||
| 479 | (display (call-with-input-file \"/shared.txt\" read-line)))"))) | 452 | (display (call-with-input-file \"/shared.txt\" read-line)))"))) |
| 480 | (list response1 response2))) | 453 | (list response1 response2))) |
| 481 | marionette)) | 454 | marionette)) |
| 455 | ;; Allow services to come up on slower machines | ||
| 456 | (let loop ((attempts 0)) | ||
| 457 | (if (= attempts 60) | ||
| 458 | (error "Service didn't come up after more than 60 seconds") | ||
| 459 | (if (equal? '("value" "hello") | ||
| 460 | (run-test)) | ||
| 461 | #t | ||
| 462 | (begin | ||
| 463 | (sleep 1) | ||
| 464 | (loop (+ 1 attempts)))))))) | ||
| 482 | 465 | ||
| 483 | (test-end)))) | 466 | (test-end)))) |
| 484 | 467 | ||
