aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/test/test/lux/concurrency/actor.lux39
1 files changed, 23 insertions, 16 deletions
diff --git a/stdlib/test/test/lux/concurrency/actor.lux b/stdlib/test/test/lux/concurrency/actor.lux
index 8ec792baf..a0e51cb09 100644
--- a/stdlib/test/test/lux/concurrency/actor.lux
+++ b/stdlib/test/test/lux/concurrency/actor.lux
@@ -8,46 +8,53 @@
["R" result])
(concurrency ["P" promise "P/" Monad<Promise>]
["T" task]
- ["&" actor #+ actor:]))
+ ["&" actor #+ actor: message:]))
lux/test)
(actor: Counter
Nat
- ((count! state self)
- Nat
- (let [state' (n.inc state)]
- (T;return [state' state'])))
+ ((handle message state self)
+ (do T;Monad<Task>
+ [#let [_ (log! "BEFORE")]
+ output (message state self)
+ #let [_ (log! "AFTER")]]
+ (wrap output)))
- ([cause state]
+ ((stop cause state)
(P/wrap (log! (if (ex;match? &;Killed cause)
(format "Counter was killed: " (%n state))
cause)))))
+(message: #export Counter
+ (count! [increment Nat] state self Nat)
+ (let [state' (n.+ increment state)]
+ (T;return [state' state'])))
+
(context: "Actors"
($_ seq
- (test "Can check where an actor is alive."
+ (test "Can check if an actor is alive."
(io;run (do Monad<IO>
- [counter (new-Counter +0)]
+ [counter (new@Counter +0)]
(wrap (&;alive? counter)))))
(test "Can kill actors."
(io;run (do Monad<IO>
- [counter (new-Counter +0)
+ [counter (new@Counter +0)
killed? (&;kill counter)]
(wrap (and killed?
(not (&;alive? counter)))))))
(test "Can poison actors."
(io;run (do Monad<IO>
- [counter (new-Counter +0)
+ [counter (new@Counter +0)
poisoned? (&;poison counter)]
(wrap (and poisoned?
(not (&;alive? counter)))))))
(test "Cannot kill an already dead actor."
(io;run (do Monad<IO>
- [counter (new-Counter +0)
+ [counter (new@Counter +0)
first-time (&;kill counter)
second-time (&;kill counter)]
(wrap (and first-time
@@ -55,7 +62,7 @@
(test "Cannot poison an already dead actor."
(io;run (do Monad<IO>
- [counter (new-Counter +0)
+ [counter (new@Counter +0)
first-time (&;kill counter)
second-time (&;poison counter)]
(wrap (and first-time
@@ -63,10 +70,10 @@
(do P;Monad<Promise>
[result (do T;Monad<Task>
- [#let [counter (io;run (new-Counter +0))]
- output-1 (count! counter)
- output-2 (count! counter)
- output-3 (count! counter)]
+ [#let [counter (io;run (new@Counter +0))]
+ output-1 (count! +1 counter)
+ output-2 (count! +1 counter)
+ output-3 (count! +1 counter)]
(wrap (and (n.= +1 output-1)
(n.= +2 output-2)
(n.= +3 output-3))))]