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)
rinckx-Rice 2017-10-05Merge branch 'master' into stagingMarius Bakke 2017-10-02gnu: youtube-dl: Update to 2017.10.01....Tobias Geerinckx-Rice 2017-09-24Merge branch 'master' into stagingMarius Bakke 2017-09-23gnu: youtube-dl: Update to 2017.09.24....Tobias Geerinckx-Rice 2017-09-22gnu: you-get: Update to 0.4.915....Feng Shu 2017-09-20gnu: Use 'modify-phases' syntax....Kei Kebreau 2017-09-20Merge branch 'master' into stagingMarius Bakke 2017-09-18gnu: youtube-dl: Update to 2017.09.15....Tobias Geerinckx-Rice 2017-09-14gnu: mpv: Update to 0.27.0....R H 2017-09-12gnu: youtube-dl: Update to 2017.09.11....Tobias Geerinckx-Rice 2017-09-12gnu: ffmpeg: Update to 3.3.4....Marius Bakke 2017-09-11gnu: youtube-dl: Update to 2017.09.10....Tobias Geerinckx-Rice 2017-09-05gnu: libmediainfo: Adjust build phases....Efraim Flashner 2017-09-04Merge branch 'master' into stagingMarius Bakke 2017-09-04gnu: Put autoconf-related phases immediately after the 'unpack phase....Kei Kebreau 2017-09-02Merge branch 'master' into stagingMarius Bakke 2017-09-02gnu: libva: Update to 1.8.3....Marius Bakke 2017-09-02gnu: ffmpeg@2.8: Update to 2.8.13....Marius Bakke 2017-09-01gnu: youtube-dl: Update to 2017.09.02....Tobias Geerinckx-Rice 2017-08-31gnu: vlc: Fix build and clean up expression....Marius Bakke 2017-08-31gnu: vlc: Recover lost phase....Marius Bakke 2017-08-30gnu: vlc: Remove obsolete test workaround....Marius Bakke 2017-08-30gnu: vlc: Build with modular qt....Marius Bakke 2017-08-29Update e-mail for Kei Kebreau....Kei Kebreau 2017-08-28gnu: srt2vtt: Update source URL....Tobias Geerinckx-Rice 2017-08-27gnu: youtube-dl: Update to 2017.08.27.1....Tobias Geerinckx-Rice 2017-08-26gnu: youtube-dl: Update to 2017.08.23....Oleg Pykhalov 2017-08-18gnu: youtube-dl: Update to 2017.08.18....Tobias Geerinckx-Rice 2017-08-15gnu: youtube-dl: Update to 2017.08.13....Tobias Geerinckx-Rice 2017-08-07gnu: vapoursynth: Don't build on aarch64-linux....Efraim Flashner 2017-08-07gnu: youtube-dl: Update to 2017.08.06....Tobias Geerinckx-Rice 2017-08-03gnu: youtube-dl: Update to 2017.07.30.1....Tobias Geerinckx-Rice 2017-07-30gnu: ffmpeg: Update to 3.3.3....Marius Bakke 2017-07-25gnu: you-get: Update to 0.4.803....Feng Shu 2017-07-23gnu: youtube-dl: Update to 2017.07.23....Tobias Geerinckx-Rice 2017-07-20gnu: openh264: Update to 1.7.0....Tobias Geerinckx-Rice 2017-07-20gnu: gnome-mpv: Update to 0.12....Tobias Geerinckx-Rice 2017-07-19gnu: mpv: Update to 0.26.0....Leo Famulari 2017-07-16gnu: youtube-dl: Update to 2017.07.15....Tobias Geerinckx-Rice 2017-07-12gnu: libaacs: Use HTTPS URL....Leo Famulari 2017-07-12gnu: libbdplus: Use HTTPS URL....Leo Famulari 2017-07-13gnu: Add simplescreenrecorder....Alex Vong 2017-07-09gnu: youtube-dl: Update to 2017.07.09....Tobias Geerinckx-Rice