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 1 commit
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
9 changes: 6 additions & 3 deletions src/sumo_store_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ find_by(DocName, Conditions, [], Limit, Offset, State) ->
fun() -> mnesia:select(DocName, MatchSpec) end;
Limit ->
fun() ->
{ManyItems, _Cont} =
mnesia:select(DocName, MatchSpec, Offset + Limit, read),
lists:sublist(ManyItems, Offset + 1, Limit)
case mnesia:select(DocName, MatchSpec, Offset + Limit, read) of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Elvis:

The expression on line 152 and column 11 is nested beyond the maximum level of 3.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Elvis:

The expression on line 152 and column 11 is nested beyond the maximum level of 3.

{ManyItems, _Cont} ->
lists:sublist(ManyItems, Offset + 1, Limit);
'$end_of_table' ->
[]
end
end
end,
case mnesia:transaction(Transaction) of
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