Skip to content

Commit

Permalink
Merge pull request #10 from nhs-riak/nhse-d32-nhskv.i17
Browse files Browse the repository at this point in the history
Test change of error response & thoas
  • Loading branch information
martinsumner authored Apr 4, 2024
2 parents ea6d509 + f8189f6 commit fbd22be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
9 changes: 7 additions & 2 deletions tests/secondary_index_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@
-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, otp}]
}],
Nodes = rt:build_cluster(3, Conf),
?assertEqual(ok, rt:wait_until_nodes_ready(Nodes)),

Expand Down
22 changes: 15 additions & 7 deletions tests/verify_2i_timeout.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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}]),
Expand All @@ -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, [])),
Expand All @@ -53,7 +54,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}]),
Expand All @@ -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, []))).

0 comments on commit fbd22be

Please sign in to comment.