remote.scm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. ;;; remote.scm -- test the remote building mechanism
  2. ;;; Copyright © 2021 Mathieu Othacehe <othacehe@gnu.org>
  3. ;;;
  4. ;;; This file is part of Cuirass.
  5. ;;;
  6. ;;; Cuirass is free software: you can redistribute it and/or modify
  7. ;;; it under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation, either version 3 of the License, or
  9. ;;; (at your option) any later version.
  10. ;;;
  11. ;;; Cuirass is distributed in the hope that it will be useful,
  12. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with Cuirass. If not, see <http://www.gnu.org/licenses/>.
  18. (use-modules (cuirass database)
  19. (cuirass specification)
  20. (gnu packages base)
  21. (guix build utils)
  22. (guix channels)
  23. (guix derivations)
  24. (guix gexp)
  25. (guix monads)
  26. (guix packages)
  27. (guix store)
  28. (tests common)
  29. (squee)
  30. (srfi srfi-64)
  31. (ice-9 match)
  32. (ice-9 threads))
  33. (define server
  34. (make-parameter #f))
  35. (define worker
  36. (make-parameter #f))
  37. (define (start-worker)
  38. (worker
  39. (match (primitive-fork)
  40. (0
  41. (setenv "REQUEST_PERIOD" "1")
  42. (execlp "cuirass" "cuirass" "remote-worker"
  43. "--server=127.0.0.1:5555"
  44. "--private-key=tests/signing-key.sec"
  45. "--public-key=tests/signing-key.pub"))
  46. (pid pid))))
  47. (define (stop-worker)
  48. (let ((worker (worker)))
  49. (kill worker SIGINT)
  50. (waitpid worker)))
  51. (define (start-server)
  52. (server
  53. (match (primitive-fork)
  54. (0
  55. (mkdir-p "tests/cache")
  56. (execlp "cuirass" "cuirass" "remote-server"
  57. (string-append "--database=" (%package-database))
  58. "--cache=tests/cache"
  59. "--private-key=tests/signing-key.sec"
  60. "--public-key=tests/signing-key.pub"))
  61. (pid pid))))
  62. (define (stop-server)
  63. (let ((server (server)))
  64. (kill server SIGINT)
  65. (waitpid server)))
  66. (define* (dummy-drv #:optional sleep)
  67. (with-store store
  68. (derivation-file-name
  69. (run-with-store store
  70. (let ((exp #~(begin
  71. (when #$sleep
  72. (sleep #$sleep))
  73. (mkdir #$output))))
  74. (gexp->derivation "foo" exp))))))
  75. (define drv
  76. (dummy-drv))
  77. (define drv-with-timeout
  78. (dummy-drv 2))
  79. (define* (make-build #:key
  80. drv
  81. output
  82. (timeout 0))
  83. `((#:derivation . ,drv)
  84. (#:eval-id . 1)
  85. (#:job-name . "fake-job")
  86. (#:system . "x86_64-linux")
  87. (#:nix-name . "fake-1.0")
  88. (#:log . "unused so far")
  89. (#:status . ,(build-status scheduled))
  90. (#:outputs . (("out" . ,output)))
  91. (#:timestamp . 1501347493)
  92. (#:timeout . ,timeout)))
  93. (test-group-with-cleanup "remote"
  94. (test-assert "db-init"
  95. (begin
  96. (test-init-db!)
  97. #t))
  98. (test-assert "fill-db"
  99. (let ((build build)
  100. (spec
  101. (specification
  102. (name "guix")
  103. (build 'hello)))
  104. (checkouts
  105. (list
  106. (checkout->channel-instance "dir1"
  107. #:name 'guix
  108. #:url "url1"
  109. #:commit "fakesha1"))))
  110. (db-add-or-update-specification spec)
  111. (db-add-evaluation "guix" checkouts
  112. #:timestamp 1501347493)
  113. (db-add-build (make-build #:drv drv
  114. #:output "fake-1"))))
  115. (test-assert "remote-server"
  116. (begin
  117. (start-server)
  118. #t))
  119. (test-assert "remote-worker"
  120. (begin
  121. (start-worker)
  122. #t))
  123. (test-assert "build done"
  124. (retry
  125. (lambda ()
  126. (eq? (assq-ref (db-get-build drv) #:status)
  127. (build-status succeeded)))
  128. #:times 10
  129. #:delay 1))
  130. (test-assert "build timeout"
  131. (begin
  132. (db-add-build (make-build #:drv drv-with-timeout
  133. #:output "fake-2"
  134. #:timeout 1))
  135. (retry
  136. (lambda ()
  137. (eq? (assq-ref (db-get-build drv-with-timeout) #:status)
  138. (build-status failed)))
  139. #:times 10
  140. #:delay 1)))
  141. (test-assert "worker restart"
  142. (begin
  143. (stop-worker)
  144. (start-worker)
  145. (db-update-build-status! drv (build-status scheduled))
  146. (retry
  147. (lambda ()
  148. (eq? (assq-ref (db-get-build drv) #:status)
  149. (build-status succeeded)))
  150. #:times 10
  151. #:delay 1)))
  152. (test-assert "clean-up"
  153. (begin
  154. (stop-worker)
  155. (stop-server))))