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)
'2021-05-31 22:04:57 +0200'>2021-05-31services: hostapd: Use package from configuration....Brice Waegeneire 2021-05-19services: opendht: Fix hang at boot....Maxim Cournoyer 2021-05-17services: Add a service for opendht....Maxim Cournoyer 2021-04-12services: ipfs: Tweak description....Ludovic Courtès 2021-04-12services: Add ipfs-service-type...Maxime Devos 2021-02-22services: tor: Add control-socket? option....Christopher Lemmer Webber 2021-01-16services: openntpd: Remove support for deprecated "-s" option....Simon South 2021-01-13services: shepherd: 'shepherd-service-type' requires documentation....Ludovic Courtès 2021-01-12services: Add keepalived service....Oleg Pykhalov 2020-11-05services: Add yggdrasil-service-type....raingloom 2020-09-24services: WPA Supplicant: Conditionally depend on D-Bus....Marius Bakke 2020-08-16services: connman-shepherd-service: Don't use short flags....Efraim Flashner 2020-07-06services: simulated-wifi: Use 'kernel-module-loader'....Brice Waegeneire 2020-07-02services: wpa-supplicant: Support specifying additional service dependencies....Marius Bakke 2020-07-02services: wpa-supplicant: Do not export the <wpa-supplicant-configuration> re......Marius Bakke 2020-05-08services: Add descriptions....Ludovic Courtès 2020-04-19services: Add 'simulated-wifi-service-type'....Ludovic Courtès 2020-04-19services: Add 'hostapd-service-type'....Ludovic Courtès 2020-03-16services: dhcpd: Use 'invoke/quiet' when validating the config file....Ludovic Courtès 2019-12-29services: dhcp-client: Ignore interfaces that cannot be activated....Brice Waegeneire