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)
1d4f643824977c3a9219644c'>plainabout -rw-r--r--acl.scm3860logplainabout -rw-r--r--ada.scm4348logplainabout -rw-r--r--admin.scm115209logplainabout -rw-r--r--adns.scm3429logplainabout -rw-r--r--agda.scm7338logplainabout -rw-r--r--aidc.scm3842logplainabout -rw-r--r--algebra.scm31576logplainabout -rw-r--r--android.scm36747logplainabout -rw-r--r--animation.scm10937logplainabout -rw-r--r--anthy.scm2821logplainabout -rw-r--r--apl.scm2132logplainabout -rw-r--r--apr.scm4303logplainabout -rw-r--r--aspell.scm13445logplainabout -rw-r--r--assembly.scm5073logplainabout -rw-r--r--astronomy.scm6682logplainabout -rw-r--r--attr.scm3169logplainabout -rw-r--r--audio.scm134175logplainabout -rw-r--r--augeas.scm2588logplainabout -rw-r--r--authentication.scm3368logplainabout -rw-r--r--autogen.scm2762logplainabout -rw-r--r--autotools.scm18617logplainabout d---------aux-files116logplain -rw-r--r--avahi.scm4243logplainabout -rw-r--r--avr.scm7071logplainabout -rw-r--r--axoloti.scm16276logplainabout -rw-r--r--backup.scm41899logplainabout -rw-r--r--base.scm57976logplainabout -rw-r--r--bash.scm15667logplainabout -rw-r--r--batik.scm8837logplainabout -rw-r--r--bdw-gc.scm4712logplainabout -rw-r--r--benchmark.scm7378logplainabout -rw-r--r--bioconductor.scm36579logplainabout -rw-r--r--bioinformatics.scm575432logplainabout -rw-r--r--bison.scm2398logplainabout -rw-r--r--bittorrent.scm18206logplainabout -rw-r--r--boost.scm7527logplainabout -rw-r--r--bootloaders.scm33912logplainabout -rw-r--r--bootstrap.scm25179logplainabout d---------bootstrap195logplain -rw-r--r--build-tools.scm11678logplainabout -rw-r--r--busybox.scm4417logplainabout -rw-r--r--c.scm9413logplainabout -rw-r--r--calcurse.scm2978logplainabout -rw-r--r--calendar.scm8406logplainabout -rw-r--r--ccache.scm2448logplainabout -rw-r--r--cdrom.scm32938logplainabout -rw-r--r--certs.scm8919logplainabout -rw-r--r--check.scm78467logplainabout -rw-r--r--chemistry.scm13749logplainabout -rw-r--r--chez.scm26143logplainabout -rw-r--r--ci.scm13473logplainabout -rw-r--r--cinnamon.scm3246logplainabout -rw-r--r--cluster.scm3502logplainabout -rw-r--r--cmake.scm7501logplainabout -rw-r--r--cobol.scm3003logplainabout -rw-r--r--code.scm29211logplainabout -rw-r--r--commencement.scm45878logplainabout -rw-r--r--compression.scm94948logplainabout -rw-r--r--compton.scm4097logplainabout -rw-r--r--conkeror.scm3730logplainabout -rw-r--r--conky.scm3210logplainabout -rw-r--r--connman.scm6893logplainabout -rw-r--r--cook.scm3594logplainabout -rw-r--r--cpio.scm2038logplainabout -rw-r--r--cpp.scm10805logplainabout -rw-r--r--cppi.scm1775logplainabout -rw-r--r--cran.scm249068logplainabout -rw-r--r--cross-base.scm21515logplainabout -rw-r--r--crypto.scm37160logplainabout -rw-r--r--cryptsetup.scm5257logplainabout -rw-r--r--cups.scm30927logplainabout -rw-r--r--curl.scm10826logplainabout -rw-r--r--cyrus-sasl.scm3023logplainabout -rw-r--r--databases.scm121436logplainabout -rw-r--r--datamash.scm2011logplainabout -rw-r--r--datastructures.scm7607logplainabout -rw-r--r--dav.scm4598logplainabout -rw-r--r--dc.scm2236logplainabout -rw-r--r--debian.scm7613logplainabout -rw-r--r--debug.scm15979logplainabout -rw-r--r--dejagnu.scm3510logplainabout -rw-r--r--dico.scm3527logplainabout -rw-r--r--dictionaries.scm11987logplainabout -rw-r--r--digest.scm2346logplainabout -rw-r--r--direct-connect.scm2606logplainabout -rw-r--r--disk.scm29307logplainabout -rw-r--r--display-managers.scm14888logplainabout -rw-r--r--django.scm31764logplainabout -rw-r--r--djvu.scm2064logplainabout -rw-r--r--dlang.scm15099logplainabout -rw-r--r--dns.scm29623logplainabout -rw-r--r--docbook.scm11743logplainabout -rw-r--r--docker.scm5368logplainabout -rw-r--r--documentation.scm10592logplainabout -rw-r--r--dunst.scm3159logplainabout -rw-r--r--dvtm.scm2311logplainabout -rw-r--r--ebook.scm11872logplainabout -rw-r--r--ed.scm2374logplainabout -rw-r--r--education.scm12661logplainabout -rw-r--r--electronics.scm9896logplainabout -rw-r--r--elf.scm9800logplainabout -rw-r--r--elixir.scm4143logplainabout -rw-r--r--emacs.scm491384logplainabout -rw-r--r--embedded.scm49388logplainabout -rw-r--r--emulators.scm54898logplainabout -rw-r--r--enchant.scm3655logplainabout -rw-r--r--engineering.scm77331logplainabout -rw-r--r--enlightenment.scm19545logplainabout -rw-r--r--entr.scm2854logplainabout -rw-r--r--erlang.scm9477logplainabout -rw-r--r--fabric-management.scm7029logplainabout -rw-r--r--fcitx.scm5006logplainabout -rw-r--r--figlet.scm1797logplainabout -rw-r--r--file-systems.scm9666logplainabout -rw-r--r--file.scm2056logplainabout -rw-r--r--finance.scm36403logplainabout -rw-r--r--firmware.scm21651logplainabout -rw-r--r--flashing-tools.scm18628logplainabout -rw-r--r--flex.scm4199logplainabout -rw-r--r--fltk.scm5769logplainabout -rw-r--r--fonts.scm57467logplainabout -rw-r--r--fontutils.scm29703logplainabout -rw-r--r--forth.scm2434logplainabout -rw-r--r--fpga.scm13853logplainabout -rw-r--r--freedesktop.scm51288logplainabout -rw-r--r--freeipmi.scm2013logplainabout -rw-r--r--fribidi.scm2002logplainabout -rw-r--r--ftp.scm10938logplainabout -rw-r--r--fvwm.scm3296logplainabout -rw-r--r--game-development.scm51315logplainabout