Skip to content

Commit bf8fd69

Browse files
Merge pull request #13932 from cloudamqp/cq_index_v2_bounds_test
Add tests for rabbit_classic_queue_index_v2:bounds/2
2 parents 87b966e + ec455d5 commit bf8fd69

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

deps/rabbit/src/rabbit_classic_queue_index_v2.erl

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
sync/1, needs_sync/1, flush/1,
2323
bounds/2, next_segment_boundary/1]).
2424

25-
%% Only used by tests
26-
-export([bounds/1]).
27-
2825
%% Used to upgrade/downgrade from/to the v1 index.
2926
-export([init_for_conversion/3]).
3027
-export([init_args/1]).
@@ -482,7 +479,7 @@ recover_index_v1_common(State0 = #qi{ queue_name = Name, dir = DirBin },
482479
{LoSeqId, HiSeqId, _} = rabbit_queue_index:bounds(V1State),
483480
%% When resuming after a crash we need to double check the messages that are both
484481
%% in the v1 and v2 index (effectively the messages below the upper bound of the
485-
%% v1 index that are about to be written to it).
482+
%% v2 index that are about to be written to it).
486483
{_, V2HiSeqId, _} = bounds(State0, undefined),
487484
SkipFun = fun
488485
(SeqId, FunState0) when SeqId < V2HiSeqId ->
@@ -1191,13 +1188,6 @@ flush_pre_publish_cache(TargetRamCount, State) ->
11911188
%% the test suite to pass. This can probably be made more accurate
11921189
%% in the future.
11931190

1194-
%% `bounds/1` is only used by tests
1195-
-spec bounds(State) ->
1196-
{non_neg_integer(), non_neg_integer(), State}
1197-
when State::state().
1198-
bounds(State) ->
1199-
bounds(State, undefined).
1200-
12011191
-spec bounds(State, non_neg_integer() | undefined) ->
12021192
{non_neg_integer(), non_neg_integer(), State}
12031193
when State::state().

deps/rabbit/test/backing_queue_SUITE.erl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -801,33 +801,35 @@ bq_queue_index1(_Config) ->
801801
TwoSegs = SegmentSize + SegmentSize,
802802
MostOfASegment = trunc(SegmentSize*0.75),
803803
SeqIdsA = lists:seq(0, MostOfASegment-1),
804+
NextSeqIdA = MostOfASegment,
804805
SeqIdsB = lists:seq(MostOfASegment, 2*MostOfASegment),
806+
NextSeqIdB = 2 * MostOfASegment + 1,
805807
SeqIdsC = lists:seq(0, trunc(SegmentSize/2)),
806808
SeqIdsD = lists:seq(0, SegmentSize*4),
807809

808810
VerifyReadWithPublishedFun = fun verify_read_with_published_v2/3,
809811

810812
with_empty_test_queue(
811813
fun (Qi0, QName) ->
812-
{0, 0, Qi1} = IndexMod:bounds(Qi0),
814+
{0, 0, Qi1} = IndexMod:bounds(Qi0, undefined),
813815
{Qi2, SeqIdsMsgIdsA} = queue_index_publish(SeqIdsA, false, Qi1),
814-
{0, SegmentSize, Qi3} = IndexMod:bounds(Qi2),
816+
{0, SegmentSize, Qi3} = IndexMod:bounds(Qi2, NextSeqIdA),
815817
{ReadA, Qi4} = IndexMod:read(0, SegmentSize, Qi3),
816818
ok = VerifyReadWithPublishedFun(false, ReadA,
817819
lists:reverse(SeqIdsMsgIdsA)),
818820
%% should get length back as 0, as all the msgs were transient
819821
{0, 0, Qi6} = restart_test_queue(Qi4, QName),
820-
{0, 0, Qi7} = IndexMod:bounds(Qi6),
822+
{NextSeqIdA, NextSeqIdA, Qi7} = IndexMod:bounds(Qi6, NextSeqIdA),
821823
{Qi8, SeqIdsMsgIdsB} = queue_index_publish(SeqIdsB, true, Qi7),
822-
{0, TwoSegs, Qi9} = IndexMod:bounds(Qi8),
824+
{0, TwoSegs, Qi9} = IndexMod:bounds(Qi8, NextSeqIdB),
823825
{ReadB, Qi10} = IndexMod:read(0, SegmentSize, Qi9),
824826
ok = VerifyReadWithPublishedFun(true, ReadB,
825827
lists:reverse(SeqIdsMsgIdsB)),
826828
%% should get length back as MostOfASegment
827829
LenB = length(SeqIdsB),
828830
BytesB = LenB * 10,
829831
{LenB, BytesB, Qi12} = restart_test_queue(Qi10, QName),
830-
{0, TwoSegs, Qi13} = IndexMod:bounds(Qi12),
832+
{0, TwoSegs, Qi13} = IndexMod:bounds(Qi12, NextSeqIdB),
831833
Qi15 = case IndexMod of
832834
rabbit_queue_index ->
833835
Qi14 = IndexMod:deliver(SeqIdsB, Qi13),
@@ -841,7 +843,7 @@ bq_queue_index1(_Config) ->
841843
{_DeletedSegments, Qi16} = IndexMod:ack(SeqIdsB, Qi15),
842844
Qi17 = IndexMod:flush(Qi16),
843845
%% Everything will have gone now because #pubs == #acks
844-
{0, 0, Qi18} = IndexMod:bounds(Qi17),
846+
{NextSeqIdB, NextSeqIdB, Qi18} = IndexMod:bounds(Qi17, NextSeqIdB),
845847
%% should get length back as 0 because all persistent
846848
%% msgs have been acked
847849
{0, 0, Qi19} = restart_test_queue(Qi18, QName),
@@ -996,7 +998,7 @@ v2_delete_segment_file_completely_acked1(_Config) ->
996998
%% Publish a full segment file.
997999
{Qi1, SeqIdsMsgIds} = queue_index_publish(SeqIds, true, Qi0),
9981000
SegmentSize = length(SeqIdsMsgIds),
999-
{0, SegmentSize, Qi2} = IndexMod:bounds(Qi1),
1001+
{0, SegmentSize, Qi2} = IndexMod:bounds(Qi1, undefined),
10001002
%% Confirm that the file exists on disk.
10011003
Path = IndexMod:segment_file(0, Qi2),
10021004
true = filelib:is_file(Path),
@@ -1024,7 +1026,7 @@ v2_delete_segment_file_partially_acked1(_Config) ->
10241026
%% Publish a partial segment file.
10251027
{Qi1, SeqIdsMsgIds} = queue_index_publish(SeqIds, true, Qi0),
10261028
SeqIdsLen = length(SeqIdsMsgIds),
1027-
{0, SegmentSize, Qi2} = IndexMod:bounds(Qi1),
1029+
{0, SegmentSize, Qi2} = IndexMod:bounds(Qi1, undefined),
10281030
%% Confirm that the file exists on disk.
10291031
Path = IndexMod:segment_file(0, Qi2),
10301032
true = filelib:is_file(Path),
@@ -1054,7 +1056,7 @@ v2_delete_segment_file_partially_acked_with_holes1(_Config) ->
10541056
{Qi1, SeqIdsMsgIdsA} = queue_index_publish(SeqIdsA, true, Qi0),
10551057
{Qi2, SeqIdsMsgIdsB} = queue_index_publish(SeqIdsB, true, Qi1),
10561058
SeqIdsLen = length(SeqIdsMsgIdsA) + length(SeqIdsMsgIdsB),
1057-
{0, SegmentSize, Qi3} = IndexMod:bounds(Qi2),
1059+
{0, SegmentSize, Qi3} = IndexMod:bounds(Qi2, undefined),
10581060
%% Confirm that the file exists on disk.
10591061
Path = IndexMod:segment_file(0, Qi3),
10601062
true = filelib:is_file(Path),

0 commit comments

Comments
 (0)