File: container.async-queue.scm

package info (click to toggle)
guile-lib 0.2.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,868 kB
  • sloc: lisp: 6,986; sh: 3,962; makefile: 195
file content (47 lines) | stat: -rw-r--r-- 1,185 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
exec ${srcdir:-.}/guile-test-env guile -s "$0" "$@"
!#

(use-modules (oop goops)
             (ice-9 threads)
             (container async-queue)
             (unit-test))

(case (catch #t
        (lambda ()
          (call-with-new-thread (lambda () 'thread)
                                (lambda (e) 'error)))
        (lambda (key . args)
          'exception))
  ((exception error)
   (display "Thread support apparently disabled, will skip this test") (newline)
   (exit 0)))

(define-class <test-async-queue> (<test-case>)
  producer
  q)

(define (producer queue)
  (do ((i 0 (+ i 1)))
      ((>= i 100))
    (usleep 100)
    (async-enqueue! queue i))
  (async-enqueue! queue #f))

(define-method (set-up-test (self <test-async-queue>))
  (slot-set! self 'q (make-async-queue))
  (slot-set! self 'producer (make-thread producer (slot-ref self 'q))))

(define-method (test-consume (self <test-async-queue>))
  (let ((q (slot-ref self 'q)))
    (do ((i 0 (+ i 1)))
        ((>= i 100))
      (assert-equal i (async-dequeue! q)))
    (assert-equal (async-dequeue! q) #f)))

(exit-with-summary (run-all-defined-test-cases))

;; Local Variables:
;; mode: scheme
;; End: