Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Just use ETap
PropEr is fun and all but its super hard to debug failing tests and its really not buying me that much in this case because I'm not really using its generators for anything. ETap is good enough here.
- Loading branch information
Showing
13 changed files
with
857 additions
and
333 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
.eunit/ | ||
deps/ | ||
ebin/ | ||
test/*.beam |
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
This file was deleted.
Oops, something went wrong.
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
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,72 @@ | ||
#! /usr/bin/env escript | ||
|
||
-define(WITH_LRU(F), tutil:with_lru(fun(LRU) -> F(LRU) end)). | ||
|
||
main([]) -> | ||
code:add_pathz("test"), | ||
code:add_pathz("ebin"), | ||
|
||
tutil:run(12, fun() -> test() end). | ||
|
||
|
||
test() -> | ||
test_lifecycle(), | ||
?WITH_LRU(test_insert_lookup), | ||
?WITH_LRU(test_insert_overwrite), | ||
?WITH_LRU(test_insert_remove), | ||
?WITH_LRU(test_member), | ||
?WITH_LRU(test_clear), | ||
|
||
ok. | ||
|
||
|
||
test_lifecycle() -> | ||
Resp = ets_lru:create(?MODULE, []), | ||
etap:fun_is( | ||
fun({ok, _LRU}) -> true; (_) -> false end, | ||
Resp, | ||
"ets_lru:create/2 returned an LRU" | ||
), | ||
{ok, LRU} = Resp, | ||
etap:is(ok, ets_lru:destroy(LRU), "Destroyed the LRU ok"). | ||
|
||
|
||
test_insert_lookup(LRU) -> | ||
ok = ets_lru:insert(LRU, foo, bar), | ||
Resp = ets_lru:lookup(LRU, foo), | ||
etap:is(Resp, {ok, bar}, "Lookup returned the inserted value"). | ||
|
||
|
||
test_insert_overwrite(LRU) -> | ||
ok = ets_lru:insert(LRU, foo, bar), | ||
Resp1 = ets_lru:lookup(LRU, foo), | ||
etap:is(Resp1, {ok, bar}, "Lookup returned the inserted value"), | ||
ok = ets_lru:insert(LRU, foo, bam), | ||
Resp2 = ets_lru:lookup(LRU, foo), | ||
etap:is(Resp2, {ok, bam}, "Lookup returned the newly inserted value"). | ||
|
||
|
||
test_insert_remove(LRU) -> | ||
ok = ets_lru:insert(LRU, foo, bar), | ||
Resp1 = ets_lru:lookup(LRU, foo), | ||
etap:is(Resp1, {ok, bar}, "Lookup returned the inserted value"), | ||
ok = ets_lru:remove(LRU, foo), | ||
Resp2 = ets_lru:lookup(LRU, foo), | ||
etap:is(Resp2, not_found, "Lookup returned not_found for removed value"). | ||
|
||
|
||
test_member(LRU) -> | ||
etap:is(false, ets_lru:member(LRU, foo), "Not yet a member: foo"), | ||
ok = ets_lru:insert(LRU, foo, bar), | ||
etap:is(true, ets_lru:member(LRU, foo), "Now a member: foo"), | ||
ok = ets_lru:remove(LRU, foo), | ||
etap:is(false, ets_lru:member(LRU, foo), "No longer a member: foo"). | ||
|
||
|
||
test_clear(LRU) -> | ||
ok = ets_lru:insert(LRU, foo, bar), | ||
Resp1 = ets_lru:lookup(LRU, foo), | ||
etap:is(Resp1, {ok, bar}, "Lookup returned the inserted value"), | ||
ok = ets_lru:clear(LRU), | ||
Resp2 = ets_lru:lookup(LRU, foo), | ||
etap:is(Resp2, not_found, "Lookup returned not_found after a clear"). |
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,69 @@ | ||
#! /usr/bin/env escript | ||
|
||
main([]) -> | ||
code:add_pathz("test"), | ||
code:add_pathz("ebin"), | ||
|
||
tutil:run(unknown, fun() -> test() end). | ||
|
||
|
||
test() -> | ||
test_named_tables(), | ||
test_max_objects(), | ||
test_max_size(), | ||
test_lifetime(), | ||
test_bad_option(), | ||
|
||
ok. | ||
|
||
|
||
test_named_tables() -> | ||
{ok, LRU} = ets_lru:create(foo, [named_tables]), | ||
etap:is(ets:info(foo_objects, size), 0, "foo_objects table exists"), | ||
etap:is(ets:info(foo_atimes, size), 0, "foo_atimes table exists"), | ||
ok = ets_lru:destroy(LRU), | ||
etap:isnt(catch ets:info(foo_objects, size), 0, "foo_objects is gone"), | ||
etap:isnt(catch ets:info(foo_atimes, size), 0, "foo_atimes is gone"), | ||
ok. | ||
|
||
|
||
test_max_objects() -> | ||
% See also: 03-limit-max-objects.t | ||
test_good([{max_objects, 5}]), | ||
test_good([{max_objects, 1}]), | ||
test_good([{max_objects, 923928342098203942}]). | ||
|
||
|
||
test_max_size() -> | ||
% See also: 04-limit-max-size.t | ||
test_good([{max_size, 1}]), | ||
test_good([{max_size, 5}]), | ||
test_good([{max_size, 23423409090923423942309423094}]). | ||
|
||
|
||
test_lifetime() -> | ||
% See also: 05-limit-lifetime.t | ||
test_good([{lifetime, 1}]), | ||
test_good([{lifetime, 5}]), | ||
test_good([{lifetime, 1244209909182409328409283409238}]). | ||
|
||
|
||
test_bad_option() -> | ||
test_bad([{bingo, bango}]), | ||
test_bad([12]), | ||
test_bad([true]). | ||
|
||
|
||
test_good(Options) -> | ||
etap:fun_is(fun | ||
({ok, LRU}) -> ets_lru:destroy(LRU), true; | ||
(_) -> false | ||
end, ets_lru:create(?MODULE, Options), "LRU created ok with options"). | ||
|
||
|
||
test_bad(Options) -> | ||
etap:fun_is(fun | ||
({invalid_option, _}) -> true; | ||
({ok, LRU}) -> ets_lru:destroy(LRU), false; | ||
(_) -> false | ||
end, catch ets_lru:create(?MODULE, Options), "LRU error with options"). |
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,26 @@ | ||
#! /usr/bin/env escript | ||
|
||
objs() -> 25. | ||
|
||
main([]) -> | ||
code:add_pathz("test"), | ||
code:add_pathz("ebin"), | ||
|
||
tutil:run(1, fun() -> test() end). | ||
|
||
|
||
test() -> | ||
{ok, LRU} = ets_lru:create(lru, [named_tables, {max_objects, objs()}]), | ||
etap:is(insert_kvs(LRU, 100 * objs()), ok, "Max object count ok"), | ||
ok = ets_lru:destroy(LRU). | ||
|
||
|
||
insert_kvs(LRU, 0) -> | ||
ok; | ||
insert_kvs(LRU, Count) -> | ||
ets_lru:insert(LRU, Count, bar), | ||
case ets:info(lru_objects, size) > objs() of | ||
true -> erlang:error(exceeded_max_objects); | ||
false -> ok | ||
end, | ||
insert_kvs(LRU, Count-1). |
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,26 @@ | ||
#! /usr/bin/env escript | ||
|
||
max_size() -> 1024. | ||
|
||
main([]) -> | ||
code:add_pathz("test"), | ||
code:add_pathz("ebin"), | ||
|
||
tutil:run(1, fun() -> test() end). | ||
|
||
|
||
test() -> | ||
{ok, LRU} = ets_lru:create(lru, [named_tables, {max_size, max_size()}]), | ||
etap:is(insert_kvs(LRU, 10000), ok, "Max size ok"), | ||
ok = ets_lru:destroy(LRU). | ||
|
||
|
||
insert_kvs(LRU, 0) -> | ||
ok; | ||
insert_kvs(LRU, Count) -> | ||
ets_lru:insert(LRU, Count, 1.5234), | ||
case ets:info(lru_objects, memory) > max_size() of | ||
true -> erlang:error(exceeded_max_size); | ||
false -> ok | ||
end, | ||
insert_kvs(LRU, Count-1). |
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,15 @@ | ||
#! /usr/bin/env escript | ||
|
||
lifetime() -> 1024. | ||
|
||
main([]) -> | ||
code:add_pathz("test"), | ||
code:add_pathz("ebin"), | ||
|
||
tutil:run(unknown, fun() -> test() end). | ||
|
||
|
||
test() -> | ||
{ok, LRU} = ets_lru:create(lru, [named_tables, {lifetime, lifetime()}]), | ||
% Figure out how to test this. | ||
ok = ets_lru:destroy(LRU). |
Oops, something went wrong.