-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a testing module for the Storage module
We test: 1. reads 2. blocking_reads 3. puts 4. blocking_reads with data not in yet
- Loading branch information
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
defmodule AnomaTest.Storage do | ||
use ExUnit.Case | ||
|
||
alias Anoma.Storage | ||
|
||
doctest(Anoma.Storage) | ||
|
||
setup_all do | ||
# base storage testing default | ||
storage = %Storage{ | ||
qualified: AnomaTest.Storage.Qualified, | ||
order: AnomaTest.Storage.Order | ||
} | ||
|
||
Storage.ensure_new(storage) | ||
[storage: storage] | ||
end | ||
|
||
describe "Direct API" do | ||
test "Empty Storage is absent", %{storage: storage} do | ||
testing_atom = :QWERTZ_abc | ||
assert Storage.get(storage, testing_atom) == :absent | ||
end | ||
|
||
test "Putting works", %{storage: storage} do | ||
testing_atom = :QWERTZ_putting | ||
assert {:atomic, :ok} = Storage.put(storage, testing_atom, 1) | ||
assert {:ok, 1} = Storage.get(storage, testing_atom) | ||
end | ||
|
||
test "block_reads work", %{storage: storage} do | ||
testing_atom = :QWERTZ_blocking | ||
assert {:atomic, :ok} = Storage.put(storage, testing_atom, 1) | ||
|
||
assert {:ok, block} = | ||
Storage.blocking_read(storage, [1, testing_atom | 0]) | ||
|
||
assert {:ok, current} = Storage.get(storage, testing_atom) | ||
assert current == block | ||
end | ||
|
||
test "block_reads can read the past", %{storage: storage} do | ||
testing_atom = :QWERTZ_blocking_past | ||
assert {:atomic, :ok} = Storage.put(storage, testing_atom, 1) | ||
assert {:atomic, :ok} = Storage.put(storage, testing_atom, 2) | ||
|
||
assert {:ok, bl_1} = | ||
Storage.blocking_read(storage, [1, testing_atom | 0]) | ||
|
||
assert {:ok, bl_2} = | ||
Storage.blocking_read(storage, [2, testing_atom | 0]) | ||
|
||
assert {:ok, curr} = Storage.get(storage, testing_atom) | ||
assert curr == bl_2 | ||
assert bl_1 + 1 == bl_2 | ||
end | ||
|
||
test "blocking_reads must accept position indicators", %{storage: s} do | ||
assert Storage.blocking_read(s, :Centuri_Republic) == :error | ||
end | ||
|
||
test "blocking_reads really do block", %{storage: storage} do | ||
testing_atom = System.unique_integer() | ||
home = self() | ||
|
||
pid = | ||
spawn(fn -> | ||
assert {:ok, value} = | ||
Storage.blocking_read(storage, [1, testing_atom | 0]) | ||
|
||
send(home, {:read, value}) | ||
end) | ||
|
||
assert Process.alive?(pid) == true | ||
Storage.put(storage, testing_atom, 1) | ||
assert_receive {:read, 1}, 100 | ||
assert Process.alive?(pid) == false | ||
end | ||
end | ||
|
||
describe "Querying by hand" do | ||
test "Reading at a known order gives results", %{storage: storage} do | ||
testing_atom = 750_089_999 | ||
Storage.write_at_order(storage, testing_atom, 10, 3) | ||
|
||
assert Storage.read_at_order(storage, testing_atom, 3) == | ||
{:atomic, [{storage.qualified, [3, testing_atom | 0], 10}]} | ||
end | ||
|
||
test "Writing at an order gives us the same testing order", %{ | ||
storage: storage | ||
} do | ||
testing_atom = 999_888_777_666 | ||
Storage.write_at_order(storage, testing_atom, 10, 3) | ||
|
||
assert Storage.read_order(storage, testing_atom) == | ||
{:atomic, [{storage.order, testing_atom, 3}]} | ||
end | ||
end | ||
end |