Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using sumo:find to retrieve an inexistent element #147

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/sumo_store_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,20 @@ find_by(DocName, Conditions, Limit, Offset, State) ->
sumo_store:result([sumo_internal:doc()], state()).
find_by(DocName, Conditions, [], Limit, Offset, State) ->
MatchSpec = build_match_spec(DocName, Conditions),
Transaction0 = fun() -> mnesia:select(DocName, MatchSpec) end,
TransactionL =
fun() ->
case mnesia:select(DocName, MatchSpec, Offset + Limit, read) of
{ManyItems, _Cont} ->
lists:sublist(ManyItems, Offset + 1, Limit);
'$end_of_table' ->
[]
end
end,
Transaction =
case Limit of
0 ->
fun() -> mnesia:select(DocName, MatchSpec) end;
Limit ->
fun() ->
{ManyItems, _Cont} =
mnesia:select(DocName, MatchSpec, Offset + Limit, read),
lists:sublist(ManyItems, Offset + 1, Limit)
end
0 -> Transaction0;
Limit -> TransactionL
end,
case mnesia:transaction(Transaction) of
{aborted, Reason} ->
Expand Down
10 changes: 10 additions & 0 deletions test/sumo_basic_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
]).

-export([
find/1,
find_all/1,
find_by/1,
delete_all/1,
Expand Down Expand Up @@ -54,6 +55,9 @@ end_per_suite(Config) ->
%%% Exported Tests Functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

find(_Config) ->
run_all_stores(fun find_module/1).

find_all(_Config) ->
run_all_stores(fun find_all_module/1).

Expand Down Expand Up @@ -84,6 +88,12 @@ init_store(Module) ->
%% Sync Timeout.
sync_timeout(Module).

find_module(Module) ->
[First, Second | _] = sumo:find_all(Module),
First = sumo:find(Module, Module:id(First)),
Second = sumo:find(Module, Module:id(Second)),
notfound = sumo:find(Module, 0).

find_all_module(Module) ->
6 = length(sumo:find_all(Module)).

Expand Down