Improve the names of the process koans

This commit is contained in:
Felipe Sere
2016-03-21 16:14:29 +00:00
parent 60b18aae1f
commit a0bb840cfc
2 changed files with 15 additions and 14 deletions

View File

@@ -1,22 +1,22 @@
defmodule Processes do defmodule Processes do
use Koans use Koans
koan "tests run in a process!" do koan "Tests run in a process" do
assert Process.alive?(:__) assert Process.alive?(:__)
end end
koan "can spew out information about a process" do koan "You can ask a process to introduce itself" do
information = Process.info(self) information = Process.info(self)
assert information[:status] == :__ assert information[:status] == :__
end end
koan "process can send messages to itself" do koan "You can send messages to any process you want" do
send self(), "hola!" send self(), "hola!"
assert_receive :__ assert_receive :__
end end
koan "a common pattern is to include the sender in the message" do koan "A common pattern is to include the sender in the message" do
pid = spawn(fn -> receive do pid = spawn(fn -> receive do
{:hello, sender} -> send sender, :how_are_you? {:hello, sender} -> send sender, :how_are_you?
_ -> assert false _ -> assert false
@@ -27,7 +27,7 @@ defmodule Processes do
assert_receive :__ assert_receive :__
end end
koan "you don't have to wait forever for messages" do koan "Waiting for a message can get boring" do
parent = self() parent = self()
spawn(fn -> receive do spawn(fn -> receive do
_anything -> flunk "I really wasn't expecting messages" _anything -> flunk "I really wasn't expecting messages"
@@ -39,20 +39,21 @@ defmodule Processes do
assert_receive :__ assert_receive :__
end end
koan "killing a process will terminate it" do koan "Killing a process will terminate it" do
pid = spawn(fn -> Process.exit(self(), :kill) end) pid = spawn(fn -> Process.exit(self(), :kill) end)
:timer.sleep(500) :timer.sleep(500)
assert Process.alive?(pid) == :__ assert Process.alive?(pid) == :__
end end
koan "killing a process kills it for good" do koan "You can also terminate other processes than yourself" do
pid = spawn(fn -> receive do end end) pid = spawn(fn -> receive do end end)
assert Process.alive?(pid)
assert Process.alive?(pid) == :__
Process.exit(pid, :kill) Process.exit(pid, :kill)
assert Process.alive?(pid) == :__ assert Process.alive?(pid) == :__
end end
koan "can trap a signal in a child process" do koan "Trapping will allow you to react to someone terminating the process" do
parent = self() parent = self()
pid = spawn(fn -> pid = spawn(fn ->
Process.flag(:trap_exit, true) Process.flag(:trap_exit, true)
@@ -67,7 +68,7 @@ defmodule Processes do
assert_receive :__ assert_receive :__
end end
koan "quitting normally has no effect" do koan "Trying to quit normally has no effect" do
pid = spawn(fn -> receive do pid = spawn(fn -> receive do
end end
end) end)
@@ -75,7 +76,7 @@ defmodule Processes do
assert Process.alive?(pid) == :__ assert Process.alive?(pid) == :__
end end
koan "quititing your own process normally does terminate it though" do koan "Exiting yourself on the other hand DOES termiante you" do
pid = spawn(fn -> receive do pid = spawn(fn -> receive do
:bye -> Process.exit(self(), :normal) :bye -> Process.exit(self(), :normal)
end end
@@ -86,7 +87,7 @@ defmodule Processes do
assert Process.alive?(pid) == :__ assert Process.alive?(pid) == :__
end end
koan "linked processes are informed about exit signals of children when trapping those signals" do koan "Parent processes can be informed about exiting children, if they trap and link" do
parent = self() parent = self()
spawn(fn -> spawn(fn ->
Process.flag(:trap_exit, true) Process.flag(:trap_exit, true)
@@ -99,7 +100,7 @@ defmodule Processes do
assert_receive :__ assert_receive :__
end end
koan "monitoring processes are informed via messages without having trapping" do koan "If you monitor your children, you'll be automatically informed for their depature" do
parent = self() parent = self()
spawn(fn -> spawn(fn ->
spawn_monitor(fn -> Process.exit(self(), :normal) end) spawn_monitor(fn -> Process.exit(self(), :normal) end)

View File

@@ -204,7 +204,7 @@ defmodule KoansHarnessTest do
:how_are_you?, :how_are_you?,
{:waited_too_long, "I am inpatient"}, {:waited_too_long, "I am inpatient"},
false, false,
false, {:multiple, [true, false]},
{:exited, :random_reason}, {:exited, :random_reason},
true, true,
false, false,