Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Add sleep order testing #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 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,30 @@

;; sleep wakeup order

(define sleep-list-mtx (make-mutex))

(define sleep-list '())

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

(define *randstate* (random-state-from-platform))

;; TODO(codemac): Curerntly this does not pass, as the "spawn time"
;; for each sleep isn't actually taken into account here. Ideally we
;; can make these sleeps small enough that the test goes quickly
;; without actually drifting across when each spawn-fiber is called.
(assert-run-fibers-terminates
(do-times
1000
(let* ((nr (random 100 *randstate*))
(n (exact->inexact (/ nr 1000))))
(spawn-fiber (lambda () (sleep n) (add-order n))))))

(assert-equal (sort sleep-list <) (reverse sleep-list))

;; fib using channels

;; sleep durations
Expand Down