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)
o. * gnu/tests/nfs.scm: Ditto. >2018-03-17gnu: curl: Ungraft....Mark H Weaver 2018-03-14gnu: curl: Add HTTP/2 support....Tobias Geerinckx-Rice 2018-03-14gnu: curl: Update replacement to 7.59.0 [security fixes]....Marius Bakke 2018-03-14gnu: kurly: Update to 1.2.1....Tobias Geerinckx-Rice 2018-03-04gnu: kurly: Declare a source file-name....Efraim Flashner 2018-01-24Merge branch 'master' into core-updatesMark H Weaver 2018-01-24gnu: curl: Update replacement to 7.58.0 [fixes CVE-2018-{1000005,1000007}]....Leo Famulari 2018-01-11Merge branch 'master' into core-updatesLeo Famulari 2018-01-08gnu: kurly: Install some documentation....Leo Famulari 2018-01-03Merge branch 'master' into core-updatesLeo Famulari 2017-12-31gnu: Add kurly....Leo Famulari 2017-12-13gnu: curl: Remove obsolete workaround....Marius Bakke 2017-12-13gnu: curl: Add a search path for CURL_CA_BUNDLE....Marius Bakke 2017-12-05gnu: curl: Remove graft for 7.57.0....Marius Bakke 2017-12-05Merge branch 'master' into core-updatesMarius Bakke 2017-11-29gnu: curl: Update to 7.57.0 [fixes CVE-2017-{8816,8817,8818}]....Leo Famulari 2017-10-24gnu: curl: Remove graft for 7.56.1....Marius Bakke 2017-10-24Merge branch 'master' into core-updatesMarius Bakke 2017-10-24gnu: curl: Update replacement to 7.56.1 [fixes CVE-2017-1000257]....Marius Bakke 2017-10-10gnu: curl: Incorporate grafted changes....Marius Bakke 2017-10-10Merge branch 'master' into core-updatesMarius Bakke 2017-10-06Merge branch 'master' into stagingMarius Bakke 2017-10-04gnu: curl: Update replacement to 7.56.0 [security fixes]....Kei Kebreau 2017-10-01gnu: curl: Update to 7.55.0....Efraim Flashner 2017-09-21gnu: curl: Update to 7.55.1....Marius Bakke 2017-08-15Merge branch 'master' into core-updatesMark H Weaver 2017-08-13gnu: curl: Fix i686 test failure....Marius Bakke 2017-08-10Merge branch 'master' into core-updatesMarius Bakke 2017-08-10gnu: curl: Update replacement to 7.55.0. [security fixes]...Marius Bakke 2017-06-18Merge branch 'master' into core-updatesMark H Weaver 2017-06-14gnu: curl: Update replacement to 7.54.1 [fixes CVE-2017-9502]....Leo Famulari 2017-05-24Merge branch 'master' into core-updatesRicardo Wurmus