Skip to content

Commit

Permalink
tests: Add sleep order testing
Browse files Browse the repository at this point in the history
  • Loading branch information
codemac committed Sep 8, 2016
1 parent 8b8b915 commit cf947ed
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/basic.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
;;;;

(define-module (tests basic)
#:use-module (fibers))
#:use-module (fibers)
#:use-module (srfi srfi-1))

(define failed? #f)

Expand Down Expand Up @@ -96,6 +97,29 @@

;; sleep wakeup order

(define sleep-list-mtx (make-mutex 'unchecked-unlock 'allow-external-unlock ))

(define sleep-list '())
(define (add-order n)
(lock-mutex sleep-list-mtx)
(set! sleep-list (cons n sleep-list))
(unlock-mutex sleep-list-mtx))

(assert-run-fibers-terminates
(begin
(spawn-fiber (lambda () (sleep 0.0) (add-order 0)))
(spawn-fiber (lambda () (sleep 0.0009) (add-order 9)))
(spawn-fiber (lambda () (sleep 0.0007) (add-order 7)))
(spawn-fiber (lambda () (sleep 0.0005) (add-order 5)))
(spawn-fiber (lambda () (sleep 0.0003) (add-order 3)))
(spawn-fiber (lambda () (sleep 0.0001) (add-order 1)))
(spawn-fiber (lambda () (sleep 0.0002) (add-order 2)))
(spawn-fiber (lambda () (sleep 0.0004) (add-order 4)))
(spawn-fiber (lambda () (sleep 0.0006) (add-order 6)))
(spawn-fiber (lambda () (sleep 0.0008) (add-order 8)))))

(assert-equal (iota 10 0) (reverse sleep-list))

;; fib using channels

;; sleep durations
Expand Down

0 comments on commit cf947ed

Please sign in to comment.