;;;; (import test) (import (only (chicken format) format) (test-utils gloss)) ;; (import futures) (test-begin "Futures") (gloss "(set! force force/future)") (set! force force/future) (test-group "simple success" (define-values (a b c) (apply values (map (lambda (vs) (future (sleep (car vs)) (apply values vs))) '((1) (2 1) (3 2 1))))) ; (test-assert (future? a)) (test-assert (future? b)) (test-assert (future? c)) ;race (test-assert (not (future-complete? a))) (test-assert (not (future-complete? b))) (test-assert (not (future-complete? c))) ; (test '(1) (receive (force a))) (test '(2 1) (receive (force b))) (test '(3 2 1) (receive (force c))) ; (test-assert (future-complete? a)) (test-assert (future-complete? b)) (test-assert (future-complete? c)) ; (test-assert (not (future-failed? a))) (test-assert (not (future-failed? b))) (test-assert (not (future-failed? c))) (gloss "Total Time should be 3 seconds: 3 concurrent threads, sleeping a maximum of 3 seconds.") ) ;FIXME test "exceptional" future (test-end "Futures") (test-exit)