diff options
| author | Andy Wingo <wingo@pobox.com> | 2016-09-10 21:14:51 +0200 |
|---|---|---|
| committer | Andy Wingo <wingo@pobox.com> | 2016-09-10 21:14:51 +0200 |
| commit | 18cb451eb6f9e6327b248cec447cf34e2b5825e2 (patch) | |
| tree | fc888157d124a9334f86f996848ae104f9ed32c3 /tests | |
| parent | run-fibers returns values from initial thread (diff) | |
| download | guile-fibers-18cb451eb6f9e6327b248cec447cf34e2b5825e2.tar.gz | |
Add initial channels tests
* tests/basic.scm (assert-run-fibers-returns): Change arg order.
(rpc, rpc-fib): Add channels tests.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basic.scm | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tests/basic.scm b/tests/basic.scm index dcae6fb..6709b7c 100644 --- a/tests/basic.scm +++ b/tests/basic.scm @@ -18,7 +18,8 @@ ;;;; (define-module (tests basic) - #:use-module (fibers)) + #:use-module (fibers) + #:use-module (fibers channels)) (define failed? #f) @@ -51,7 +52,7 @@ 1.0 internal-time-units-per-second)) (apply values vals)))))) -(define-syntax-rule (assert-run-fibers-returns exp expected ...) +(define-syntax-rule (assert-run-fibers-returns (expected ...) exp) (begin (call-with-values (lambda () (assert-run-fibers-terminates exp)) (lambda run-fiber-return-vals @@ -124,11 +125,21 @@ (iota count))) (assert-run-fibers-terminates (test-wakeup-order 10))) -(assert-run-fibers-returns 1 1) +(assert-run-fibers-returns (1) 1) -;; sleep wakeup order +(define-syntax-rule (rpc exp) + (let ((ch (make-channel))) + (spawn-fiber (lambda () (put-message ch exp))) + (get-message ch))) -;; fib using channels +(assert-run-fibers-returns (1) (rpc 1)) + +(define (rpc-fib n) + (rpc (if (< n 2) + 1 + (+ (rpc-fib (- n 1)) (rpc-fib (- n 2)))))) + +(assert-run-fibers-returns (75025) (rpc-fib 24)) ;; sleep durations |
