Skip to content

Commit ab7a378

Browse files
committed
good tests no sleepy
1 parent 3f88e87 commit ab7a378

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

test/dispatcher.lisp

+30-22
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,34 @@
77

88
(deftest test-dispatcher-balanced ()
99
"Make sure all the workers share equally for similarly timed jobs."
10-
(define-actor counter ((c 0)) (increment)
11-
(sleep 0.025)
12-
(incf c increment))
13-
14-
(let ((actor (counter :workers 2)))
15-
(dotimes (i 40) (send actor 1))
16-
(close-actor actor)
17-
(let ((stores (join-actor actor)))
18-
(is (~= (first stores) (second stores))))))
10+
(let ((lock (bt2:make-lock)))
11+
(define-actor counter ((c 0)) (increment)
12+
(bt2:with-lock-held (lock)
13+
(incf c increment)))
14+
15+
(let ((actor (counter :workers 2)))
16+
(bt2:with-lock-held (lock)
17+
(dotimes (i 40) (send actor 1)))
18+
(close-actor actor)
19+
(let ((stores (join-actor actor)))
20+
(is (~= (first stores) (second stores)))))))
1921

2022
(deftest test-dispatcher-unbalanced ()
2123
"Make sure a worker with slow jobs doesn't fill up."
22-
(define-actor sleeper ((c 0)) (time)
23-
(sleep time)
24-
(incf c))
25-
26-
(let ((actor (sleeper :workers 2)))
27-
(dotimes (i 5)
28-
(send (first (thespis::dispatcher-workers actor)) 5))
29-
(dotimes (i 19) (sleep 0.001) (send actor 0))
30-
(is (= 20 (ask actor 0)))
31-
(destroy-actor actor)))
24+
(define-actor waiter ((c 0)) (lock)
25+
(if (bt2:lockp lock)
26+
(bt2:with-lock-held (lock)
27+
(incf c))
28+
(incf c)))
29+
30+
(let ((actor (waiter :workers 2))
31+
(lock (bt2:make-lock)))
32+
(bt2:with-lock-held (lock)
33+
(dotimes (i 10)
34+
(send (first (thespis::dispatcher-workers actor)) lock))
35+
(dotimes (i 5)
36+
(send actor nil)))
37+
(is (equal '((10 5)) (close-and-join-actors actor)))))
3238

3339
(deftest test-dispatcher-registry ()
3440
"Test registering a dispatcher with a global name."
@@ -53,7 +59,10 @@
5359

5460
(send :my-counter 1)
5561
(send :my-counter 1)
56-
(is (= 6 (reduce #'+ (join-actor (close-actor :my-counter))))))
62+
63+
(is (= 6 (reduce #'+
64+
(mapcar (lambda (x) (or x 0))
65+
(join-actor (close-actor :my-counter)))))))
5766

5867
(deftest test-dispatcher-close-and-join ()
5968
(define-actor counter ((c 0)) (increment)
@@ -65,8 +74,7 @@
6574

6675
(deftest test-closed-actor ()
6776
"Sending messages to a closed dispatcher signals an error."
68-
(define-actor closer () (x)
69-
x)
77+
(define-actor closer () (x) x)
7078

7179
(let ((actor (closer :workers 2)))
7280
(close-actor actor)

test/fuzz.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:thespis/test/basic
99
:stream (make-broadcast-stream)))))
1010

11-
(deftest fuzz-dispatcher-tests (&optional (times 4))
11+
(deftest fuzz-dispatcher-tests (&optional (times 1024))
1212
"Don't try as many reps here because it is too slow."
1313
(dotimes (i times)
1414
(is (fiasco:run-tests

0 commit comments

Comments
 (0)