aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-workers)
  #:use-module (guix workers)
  #:use-module (ice-9 threads)
  #:use-module (srfi srfi-64))

(test-begin "workers")

(test-equal "enqueue"
  4242
  (let* ((pool   (make-pool))
         (result 0)
         (1+!    (let ((lock (make-mutex)))
                   (lambda ()
                     (with-mutex lock
                       (set! result (+ result 1)))))))
    (let loop ((i 4242))
      (unless (zero? i)
        (pool-enqueue! pool 1+!)
        (loop (- i 1))))
    (let poll ()
      (unless (pool-idle? pool)
        (pk 'busy result)
        (sleep 1)
        (poll)))
    result))

;; Same as above, but throw exceptions within the workers and make sure they
;; remain alive.
(test-equal "exceptions"
  4242
  (let* ((pool   (make-pool 10))
         (result 0)
         (1+!    (let ((lock (make-mutex)))
                   (lambda ()
                     (with-mutex lock
                       (set! result (+ result 1)))))))
    (let loop ((i 10))
      (unless (zero? i)
        (pool-enqueue! pool (lambda ()
                              (throw 'whatever)))
        (loop (- i 1))))
    (let loop ((i 4242))
      (unless (zero? i)
        (pool-enqueue! pool 1+!)
        (loop (- i 1))))
    (let poll ()
      (unless (pool-idle? pool)
        (pk 'busy result)
        (sleep 1)
        (poll)))
    result))

(test-end)
ror' warns about file/module name mismatches....Ludovic Courtès 2019-04-19guix build: Accept multiple '-s' options....Ludovic Courtès 2019-04-15guix build: Fix relative file name canonicalization for '--root'....Ludovic Courtès 2019-02-04daemon: Rename 'NIX_STATE_DIR' and 'NIX_DB_DIR' environment variables....Ludovic Courtès 2018-10-09guix build: '-f' accepts file-like objects....Ludovic Courtès 2018-05-04guix build: Nicely report unbound variables with hints....Ludovic Courtès 2018-03-13gnu: time: Update to 1.9....Efraim Flashner 2017-11-11tests: Refer to "time@1.8"....Ludovic Courtès 2017-05-01packages: Remove support for PACKAGE-VERSION deprecated syntax....Ludovic Courtès 2017-04-21store: 'GUIX_DAEMON_SOCKET' can now be a URI....Ludovic Courtès 2017-03-19gnu: Rename "guile-next" to "guile"....Ludovic Courtès 2016-10-03tests: Adjust 'guix build -S' test for source-less packages....Ludovic Courtès 2016-09-06packages: Add 'package-superseded' and associated support....Ludovic Courtès 2016-03-08packages: Support the deprecated "NAME-VERSION" syntax....Ludovic Courtès 2016-03-03guix build: -S returns the replacement's source....Ludovic Courtès 2016-03-02utils: Use '@' for separating package names and version numbers....Mathieu Lirzin 2016-03-02tests: Disable grafts by default....Ludovic Courtès 2016-02-01guix build: Add '--with-input'....Ludovic Courtès