-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lisp
63 lines (57 loc) · 2.27 KB
/
test.lisp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(uiop:define-package :async/test
(:mix :async/async :fiveam :cl :iterate)
(:export #:async-executor))
(in-package :async/test)
(def-suite async-executor)
(def-test one-job-one-thread (:suite async-executor)
(is (eq :success
(asynchronously (1)
:success))))
(def-test await-a-job (:suite async-executor)
(let* ((status :initial))
(is (eq :final
(asynchronously (1)
(await (async ()
(setf status (if (eq status :initial)
:second
:failure))))
(setf status (if (eq status :second)
:final
:failure)))))
(is (eq status :final))))
(def-test multiple-concurrent-jobs (:suite async-executor)
(is (= 27
(asynchronously (2)
(let* ((one (async ()
(sleep 1)
1))
(two (async ()
(+ 1 (await one))))
(twelve (async ()
(* 6 (await two))))
(three (async ()
(sleep 1)
3))
(fifteen (async ()
(* 5 (await three)))))
(+ (await twelve) (await fifteen)))))))
(def-test job-seq-syntax (:suite async-executor)
(is (= 3 (with-executor (1)
(wait-for (job-seq (async () 1)
(lambda (one) (+ one 1))
(lambda (two) (* two two))
(lambda (four) (- four 1))))))))
(def-test multiple-concurrent-jobs-many-times (:suite async-executor)
(with-executor (4)
(labels ((make-job-sums-to-2^ (n)
(if (= n 0)
(async () 1)
(let* ((left (make-job-sums-to-2^ (1- n)))
(right (make-job-sums-to-2^ (1- n))))
(async () (+ (await left) (await right)))))))
(let* ((jobs (iter outer (for i from 0 to 8)
(collect (make-job-sums-to-2^ i)))))
(iter (for job in jobs)
(for i from 0 to 8)
(is (= (expt 2 i) (wait-for job)))
(finish-output *test-dribble*))))))