Fix issue with use of ets:next

ets:next is not StartInclusive - so we shouldn't use ets:next when querying the ledger cache, until it has been confirmed thta a matching key to the StartKey is not present.

This reoslves the intermittently failing unit test which highlighted this (and also makes that intermittent failure a permanent failure by expanding the test cases it covers).
This commit is contained in:
Martin Sumner 2018-04-30 15:20:37 +01:00
parent 12dae9209a
commit 941d4d2577

View file

@ -1125,7 +1125,14 @@ readycache_forsnapshot(LedgerCache, Query) ->
end.
scan_table(Table, StartKey, EndKey) ->
scan_table(Table, StartKey, EndKey, [], infinity, 0).
case ets:lookup(Table, StartKey) of
[] ->
scan_table(Table, StartKey, EndKey, [], infinity, 0);
[{StartKey, StartVal}] ->
SQN = leveled_codec:strip_to_seqonly({StartKey, StartVal}),
scan_table(Table, StartKey, EndKey,
[{StartKey, StartVal}], SQN, SQN)
end.
scan_table(Table, StartKey, EndKey, Acc, MinSQN, MaxSQN) ->
case ets:next(Table, StartKey) of
@ -1884,12 +1891,18 @@ foldobjects_vs_foldheads_bybucket_testto() ->
?assertMatch(true,
lists:usort(KeyHashList2B) == lists:usort(KeyHashList2D)),
CheckSplitQueryFun =
fun(SplitInt) ->
io:format("Testing SplitInt ~w~n", [SplitInt]),
SplitIntEnd = "Key" ++ integer_to_list(SplitInt) ++ "|",
SplitIntStart = "Key" ++ integer_to_list(SplitInt + 1),
{async, HTFolder2E} =
book_returnfolder(Bookie1,
{foldheads_bybucket,
?STD_TAG,
"BucketB",
{"Key", "Key4|"},
{"Key", SplitIntEnd},
FoldHeadsFun,
true, false, false}),
KeyHashList2E = HTFolder2E(),
@ -1898,7 +1911,7 @@ foldobjects_vs_foldheads_bybucket_testto() ->
{foldheads_bybucket,
?STD_TAG,
"BucketB",
{"Key5", "Key|"},
{SplitIntStart, "Key|"},
FoldHeadsFun,
true, false, false}),
KeyHashList2F = HTFolder2F(),
@ -1909,9 +1922,18 @@ foldobjects_vs_foldheads_bybucket_testto() ->
[length(KeyHashList2B),
length(KeyHashList2E),
length(KeyHashList2F)]),
?assertMatch(true,
lists:usort(KeyHashList2B) ==
lists:usort(KeyHashList2E ++ KeyHashList2F)),
CompareL = lists:usort(KeyHashList2E ++ KeyHashList2F),
SubtractL = lists:subtract(KeyHashList2B, CompareL),
case length(SubtractL) of
0 ->
io:format("Test looks like passing~n");
_L ->
io:format("Failure on SplitInt ~w~n", [SplitInt])
end,
?assertMatch(true, lists:usort(KeyHashList2B) == CompareL)
end,
lists:foreach(CheckSplitQueryFun, [1, 4, 8, 300, 100, 400]),
ok = book_close(Bookie1),
reset_filestructure().