Initial Commit
This commit is contained in:
15
kv/test/kv/bucket_test.exs
Normal file
15
kv/test/kv/bucket_test.exs
Normal file
@@ -0,0 +1,15 @@
|
||||
defmodule KV.BucketTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
setup do
|
||||
bucket = start_supervised!(KV.Bucket)
|
||||
%{bucket: bucket}
|
||||
end
|
||||
|
||||
test "stores values by key", %{bucket: bucket} do
|
||||
assert KV.Bucket.get(bucket, "milk") == nil
|
||||
|
||||
KV.Bucket.put(bucket, "milk", 3)
|
||||
assert KV.Bucket.get(bucket, "milk") == 3
|
||||
end
|
||||
end
|
||||
42
kv/test/kv/registry_test.exs
Normal file
42
kv/test/kv/registry_test.exs
Normal file
@@ -0,0 +1,42 @@
|
||||
defmodule KV.RegistryTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
setup context do
|
||||
_ = start_supervised!({KV.Registry, name: context.test})
|
||||
%{registry: context.test}
|
||||
end
|
||||
|
||||
test "spawns buckets", %{registry: registry} do
|
||||
assert KV.Registry.lookup(registry, "shopping") == :error
|
||||
|
||||
KV.Registry.create(registry, "shopping")
|
||||
assert {:ok, bucket} = KV.Registry.lookup(registry, "shopping")
|
||||
|
||||
KV.Bucket.put(bucket, "milk", 1)
|
||||
assert KV.Bucket.get(bucket, "milk") == 1
|
||||
end
|
||||
|
||||
test "removes buckets on exit", %{registry: registry} do
|
||||
KV.Registry.create(registry, "shopping")
|
||||
{:ok, bucket} = KV.Registry.lookup(registry, "shopping")
|
||||
Agent.stop(bucket)
|
||||
# Do a call to ensure the registry processed the DOWN message
|
||||
_ = KV.Registry.create(registry, "bogus")
|
||||
assert KV.Registry.lookup(registry, "shopping") == :error
|
||||
end
|
||||
|
||||
test "removes bucket on crash", %{registry: registry} do
|
||||
KV.Registry.create(registry, "shopping")
|
||||
{:ok, bucket} = KV.Registry.lookup(registry, "shopping")
|
||||
|
||||
# Stop the bucket with non-normal reason
|
||||
# If a process terminates with a reason other than :normal, all linked processes
|
||||
# receive an EXIT signal, causing the linked process to
|
||||
# also terminate unless it is trapping exits.
|
||||
Agent.stop(bucket, :shutdown)
|
||||
|
||||
# Do a call to ensure the registry processed the DOWN message
|
||||
_ = KV.Registry.create(registry, "bogus")
|
||||
assert KV.Registry.lookup(registry, "shopping") == :error
|
||||
end
|
||||
end
|
||||
1
kv/test/test_helper.exs
Normal file
1
kv/test/test_helper.exs
Normal file
@@ -0,0 +1 @@
|
||||
ExUnit.start()
|
||||
Reference in New Issue
Block a user