File 2453-mnesia-more-select_reverse-coverage.patch of Package erlang
From 9f5a4f59d440f6cb5f72df07cda94d7ca00710b3 Mon Sep 17 00:00:00 2001
From: Bentheburrito <github.arson718@passmail.net>
Date: Fri, 11 Apr 2025 11:20:20 -0700
Subject: [PATCH 3/8] mnesia: more select_reverse coverage
---
lib/mnesia/doc/guides/mnesia_chap4.md | 2 +-
lib/mnesia/test/mnesia_config_test.erl | 3 +++
lib/mnesia/test/mnesia_trans_access_test.erl | 24 ++++++++++++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/lib/mnesia/doc/guides/mnesia_chap4.md b/lib/mnesia/doc/guides/mnesia_chap4.md
index e50b21b60a..57fc830f27 100644
--- a/lib/mnesia/doc/guides/mnesia_chap4.md
+++ b/lib/mnesia/doc/guides/mnesia_chap4.md
@@ -852,7 +852,7 @@ collect.
There is also [`select_reverse/1,2,3,4`](`mnesia:select_reverse/2`), should you
want to traverse from the end of the result set. This is only applicable to
`ram_copies` or `disc_copies` tables of type `ordered_set`. For other table
-configurations, it behaves the same as `mnesia:select/1,2,3,4`.
+configurations, it behaves the same as [`mnesia:select/1,2,3,4`](`mnesia:select/2`).
> #### Warning {: .warning }
>
diff --git a/lib/mnesia/test/mnesia_config_test.erl b/lib/mnesia/test/mnesia_config_test.erl
index be90fb446c..bc7440a256 100644
--- a/lib/mnesia/test/mnesia_config_test.erl
+++ b/lib/mnesia/test/mnesia_config_test.erl
@@ -211,6 +211,9 @@ do_access(Kind, Tab, RecName, Attr, Nodes) ->
Twos = [{RecName, 2, 20}, {RecName, 2, 21}, {RecName, 2, 22}],
?match(Twos, lists:sort(mnesia:read(Tab, 2, read))),
+
+ TwosPat = [{{RecName, 2, '_'}, [], ['$_']}],
+ ?match(Twos, lists:sort(mnesia:select_reverse(Tab, TwosPat, read))),
?match(ok, mnesia:delete_object(Tab, {RecName, 2, 21}, sticky_write)),
diff --git a/lib/mnesia/test/mnesia_trans_access_test.erl b/lib/mnesia/test/mnesia_trans_access_test.erl
index 3347388d28..a1cbf88022 100644
--- a/lib/mnesia/test/mnesia_trans_access_test.erl
+++ b/lib/mnesia/test/mnesia_trans_access_test.erl
@@ -467,6 +467,13 @@ select14(Config) when is_list(Config) ->
Test(Tab2),
Test(Tab3),
Test(Tab4),
+
+ OneRec = {Tab1, 1, 2},
+ TwoRec = {Tab1, 2, 3},
+ All = [OneRec, TwoRec],
+ AllPat = [{'_', [], ['$_']}],
+ ?match(All, rpc:call(Node1, mnesia, ets, [fun() -> Loop(Tab1, AllPat) end])),
+
?verify_mnesia(Nodes, []).
%% select_reverse
@@ -575,6 +582,23 @@ select_reverse14(Config) when is_list(Config) ->
end
end),
+ case TabType of
+ ets ->
+ ?match(All, mnesia:sync_dirty(fun() -> mnesia:select_reverse(Tab, AllPat, read) end)),
+ mnesia:sync_dirty(fun() ->
+ {[TwoRec], Cont} = mnesia:select_reverse(Tab, AllPat, 1, read),
+ {[OneRec], _Cont} = mnesia:select_reverse(Cont)
+ end);
+ dets ->
+ %% DETS will behave like a normal `select`
+ ?match([OneRec,TwoRec], mnesia:sync_dirty(fun() -> mnesia:select_reverse(Tab, AllPat, read) end)),
+ mnesia:sync_dirty(fun() ->
+ {[OneRec], Cont} = mnesia:select_reverse(Tab, AllPat, 1, read),
+ {[TwoRec], _Cont} = mnesia:select_reverse(Cont)
+ end)
+ end,
+
+
?match({aborted, _}, Trans(fun() -> mnesia:select_reverse(Tab, {match, '$1', 2},1,read) end)),
?match({aborted, _}, Trans(fun() -> mnesia:select_reverse(Tab, [{'_', [], '$1'}],1,read) end)),
?match({aborted, _}, Trans(fun() -> mnesia:select_reverse(sune) end)),
--
2.43.0