processes.scm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; 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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-processes)
  19. #:use-module (guix scripts processes)
  20. #:use-module (guix store)
  21. #:use-module (guix derivations)
  22. #:use-module (guix packages)
  23. #:use-module (guix gexp)
  24. #:use-module ((guix utils) #:select (call-with-temporary-directory))
  25. #:use-module (gnu packages bootstrap)
  26. #:use-module (guix tests)
  27. #:use-module (srfi srfi-1)
  28. #:use-module (srfi srfi-64)
  29. #:use-module (rnrs bytevectors)
  30. #:use-module (rnrs io ports)
  31. #:use-module (ice-9 match)
  32. #:use-module (ice-9 threads))
  33. (test-begin "processes")
  34. (test-assert "not a client"
  35. (not (find (lambda (session)
  36. (= (getpid)
  37. (process-id (daemon-session-client session))))
  38. (daemon-sessions))))
  39. (test-assert "client"
  40. (with-store store
  41. (let* ((session (find (lambda (session)
  42. (= (getpid)
  43. (process-id (daemon-session-client session))))
  44. (daemon-sessions)))
  45. (daemon (daemon-session-process session)))
  46. (and (kill (process-id daemon) 0)
  47. (string-suffix? "guix-daemon" (first (process-command daemon)))))))
  48. (test-assert "client + lock"
  49. (with-store store
  50. (call-with-temporary-directory
  51. (lambda (directory)
  52. (let* ((token1 (string-append directory "/token1"))
  53. (token2 (string-append directory "/token2"))
  54. (exp #~(begin #$(random-text)
  55. (mkdir #$token1)
  56. (let loop ()
  57. (unless (file-exists? #$token2)
  58. (sleep 1)
  59. (loop)))
  60. (mkdir #$output)))
  61. (guile (package-derivation store %bootstrap-guile))
  62. (drv (run-with-store store
  63. (gexp->derivation "foo" exp
  64. #:guile-for-build guile)))
  65. (thread (call-with-new-thread
  66. (lambda ()
  67. (build-derivations store (list drv)))))
  68. (_ (let loop ()
  69. (unless (file-exists? token1)
  70. (usleep 200)
  71. (loop))))
  72. (session (find (lambda (session)
  73. (= (getpid)
  74. (process-id (daemon-session-client session))))
  75. (daemon-sessions)))
  76. (locks (daemon-session-locks-held (pk 'session session))))
  77. (call-with-output-file token2 (const #t))
  78. (equal? (list (string-append (derivation->output-path drv) ".lock"))
  79. locks))))))
  80. (test-end "processes")