From b175fdc71c7620f7b68d56afd86a3d965bac6d48 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Fri, 16 Feb 2024 13:52:54 +0000 Subject: [PATCH 1/3] Test change of error response & thoas --- tests/secondary_index_tests.erl | 10 ++++++++-- tests/verify_2i_timeout.erl | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/secondary_index_tests.erl b/tests/secondary_index_tests.erl index c3d10077b..a3b3963d1 100644 --- a/tests/secondary_index_tests.erl +++ b/tests/secondary_index_tests.erl @@ -34,8 +34,14 @@ -define(KEYS(A,B,G1,G2), [int_to_key(N) || N <- lists:seq(A,B), G1, G2]). confirm() -> - Conf = [{riak_core, [{default_bucket_props, [{allow_mult, true}, - {dvv_enabled, true}]}]}], + Conf = + [{riak_core, + [{default_bucket_props, + [{allow_mult, true}, {dvv_enabled, true}]} + ]}, + {riak_kv, + [{secondary_index_json, thoas}] + }], Nodes = rt:build_cluster(3, Conf), ?assertEqual(ok, rt:wait_until_nodes_ready(Nodes)), diff --git a/tests/verify_2i_timeout.erl b/tests/verify_2i_timeout.erl index ba03d5ab1..c76f8128c 100644 --- a/tests/verify_2i_timeout.erl +++ b/tests/verify_2i_timeout.erl @@ -53,7 +53,7 @@ confirm() -> lager:info("Query error with ErrCode ~p", [ErrCode]), - ?assertEqual(true, ErrCode >= 500), + ?assertEqual(true, ErrCode == 503), ?assertMatch({match, _}, re:run(Body, "request timed out|{error,timeout}")), %% shows the app.config timeout HttpRes = http_query(Http, Query, [{timeout, 5000}]), From 261645609eaa2198a54c03628c27a566db783998 Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Tue, 27 Feb 2024 14:32:35 +0000 Subject: [PATCH 2/3] Switch thoas -> json --- tests/secondary_index_tests.erl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/secondary_index_tests.erl b/tests/secondary_index_tests.erl index a3b3963d1..ea640aafd 100644 --- a/tests/secondary_index_tests.erl +++ b/tests/secondary_index_tests.erl @@ -39,8 +39,7 @@ confirm() -> [{default_bucket_props, [{allow_mult, true}, {dvv_enabled, true}]} ]}, - {riak_kv, - [{secondary_index_json, thoas}] + {riak_kv, [{secondary_index_json, otp}] }], Nodes = rt:build_cluster(3, Conf), ?assertEqual(ok, rt:wait_until_nodes_ready(Nodes)), From f8189f618c611f5acd404dd86f7b7f998863849d Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Wed, 28 Feb 2024 12:27:22 +0000 Subject: [PATCH 3/3] Make KeyCount higher As otherwise, on very fast machines, query may complete before 1ms timeout --- tests/verify_2i_timeout.erl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/verify_2i_timeout.erl b/tests/verify_2i_timeout.erl index c76f8128c..55070e0be 100644 --- a/tests/verify_2i_timeout.erl +++ b/tests/verify_2i_timeout.erl @@ -27,6 +27,7 @@ -define(FOO, <<"foo">>). confirm() -> + KeyCount = 8000, inets:start(), Config = [{riak_kv, [{secondary_index_timeout, 1}]}], %% ludicrously short, should fail always Nodes = rt:build_cluster([{current, Config}, {current, Config}, {current, Config}]), @@ -36,9 +37,9 @@ confirm() -> Http = rt:http_url(hd(Nodes)), [put_an_object(PBPid, N) || N <- lists:seq(0, 500)], - [put_an_object(PBPid, int_to_key(N), N, ?FOO) || N <- lists:seq(501, 5000)], + [put_an_object(PBPid, int_to_key(N), N, ?FOO) || N <- lists:seq(501, KeyCount)], - ExpectedKeys = lists:sort([int_to_key(N) || N <- lists:seq(0, 5000)]), + ExpectedKeys = lists:sort([int_to_key(N) || N <- lists:seq(0, KeyCount)]), Query = {<<"$bucket">>, ?BUCKET}, %% Verifies that the app.config param was used ?assertEqual({error, timeout}, stream_pb(PBPid, Query, [])), @@ -65,8 +66,15 @@ confirm() -> pass. stream_http(Http, Query, ExpectedKeys) -> - Res = http_stream(Http, Query, []), - ?assert(lists:member({<<"error">>,<<"timeout">>}, Res)), - Res2 = http_stream(Http, Query, [{timeout, 5000}]), - ?assertEqual(ExpectedKeys, lists:sort(proplists:get_value(<<"keys">>, Res2, []))). + {TC, Res} = timer:tc(fun() -> http_stream(Http, Query, []) end), + case lists:keyfind(<<"keys">>, 1, Res) of + {<<"keys">>, Keys} -> + lager:info( + "Stream returned in ~w microseconds result with keys ~p", + [TC, length(Keys)]); + _ -> + ok + end, + Res2 = http_stream(Http, Query, [{timeout, 5000}]), + ?assertEqual(ExpectedKeys, lists:sort(proplists:get_value(<<"keys">>, Res2, []))).