Skip to content

Commit 5e5fe58

Browse files
committed
dispatcher tests
1 parent 44cc774 commit 5e5fe58

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

test/dispatcher.lisp

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
(defun ~= (a b)
66
(>= 2 (abs (- a b))))
77

8-
(deftest test-dispatcher-balancing ()
9-
"Make sure all the workers share."
8+
(deftest test-dispatcher-balanced ()
9+
"Make sure all the workers share equally for similarly timed jobs."
1010
(define-actor counter ((c 0)) (increment)
1111
(sleep 0.025)
1212
(incf c increment))
@@ -15,8 +15,10 @@
1515
(dotimes (i 40) (send actor 1))
1616
(close-actor actor)
1717
(let ((stores (join-actor actor)))
18-
(is (~= (first stores) (second stores)))))
18+
(is (~= (first stores) (second stores))))))
1919

20+
(deftest test-dispatcher-unbalanced ()
21+
"Make sure a worker with slow jobs doesn't fill up."
2022
(define-actor sleeper ((c 0)) (time)
2123
(sleep time)
2224
(incf c))
@@ -28,6 +30,7 @@
2830
(is (equal '((5 20)) (close-and-join-actors actor)))))
2931

3032
(deftest test-dispatcher-registry ()
33+
"Test registering a dispatcher with a global name."
3134
(define-actor counter ((c 0)) (increment)
3235
(incf c increment))
3336

test/fuzz.lisp

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,13 @@
44
(deftest fuzz-basic-tests (&optional (times 1024))
55
"Detect rare race conditions by brute force."
66
(dotimes (i times)
7-
(let ((*standard-output* (make-broadcast-stream)))
8-
(is (fiasco:run-tests :thespis/test/basic)))))
7+
(is (fiasco:run-tests
8+
:thespis/test/basic
9+
:stream (make-broadcast-stream)))))
10+
11+
(deftest fuzz-dispatcher-tests (&optional (times 16))
12+
"Don't try as many reps here because it is too slow."
13+
(dotimes (i times)
14+
(is (fiasco:run-tests
15+
:thespis/test/dispatcher
16+
:stream (make-broadcast-stream)))))

thespis.asd

+2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
:depends-on (#:thespis #:fiasco)
1212
:components ((:module "test"
1313
:components ((:file "basic")
14+
(:file "dispatcher")
1415
(:file "fuzz"))))
1516
:perform (asdf:test-op
1617
(o c)
1718
(multiple-value-bind (stat result)
1819
(uiop:symbol-call :fiasco :run-tests
1920
'(:thespis/test/basic
21+
:thespis/test/dispatcher
2022
:thespis/test/fuzz))
2123
(print result)
2224
(assert (eql t stat)))))

0 commit comments

Comments
 (0)