27 lines
787 B
Elixir
27 lines
787 B
Elixir
defmodule Scopes.CoreActorTest do
|
|
use ExUnit.Case, async: true
|
|
alias Scopes.Core.Actor
|
|
|
|
describe "actors:" do
|
|
test "basic-life-cycle" do
|
|
Registry.start_link(keys: :unique, name: Actors)
|
|
this = self()
|
|
|
|
ac = Actor.create(fn msg -> send(this, msg) end)
|
|
Actor.register(ac, Actors, :demo, [])
|
|
# or: ac = Actor.create(fn msg -> send(this, msg) end, Actors, :demo)
|
|
|
|
Actor.send(ac, "Hello Actor!")
|
|
assert_receive "Hello Actor!"
|
|
|
|
[{pid, _value}] = Registry.lookup(Actors, :demo)
|
|
assert pid == ac
|
|
|
|
Actor.become(ac, fn _msg -> send(this, "Goodbye") end)
|
|
Actor.send(ac, "Hello Actor!")
|
|
Actor.stop(ac)
|
|
assert_receive "Goodbye"
|
|
refute_received msg, "unhandled message(s): #{inspect(msg)}"
|
|
end
|
|
end
|
|
end
|