mirror of
https://github.com/valitydev/riak_test.git
synced 2024-11-06 16:45:29 +00:00
Merge pull request #341 from basho/gh610-2i-timeout
Add test for timeout of 2i queriess
This commit is contained in:
commit
ccd1021657
@ -22,7 +22,7 @@
|
||||
-export([confirm/0]).
|
||||
-export([put_an_object/2, put_an_object/4, int_to_key/1,
|
||||
stream_pb/2, stream_pb/3, pb_query/3, http_query/2,
|
||||
http_query/3, http_stream/3, int_to_field1_bin/1]).
|
||||
http_query/3, http_stream/3, int_to_field1_bin/1, url/2]).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include_lib("riakc/include/riakc.hrl").
|
||||
|
||||
@ -129,6 +129,8 @@ stream_loop(Acc) ->
|
||||
{_Ref, ?INDEX_STREAM_RESULT{terms=Results}} ->
|
||||
Acc2 = orddict:update(results, fun(Existing) -> Existing++Results end, Results, Acc),
|
||||
stream_loop(Acc2);
|
||||
{_Ref, {error, <<"{error,timeout}">>}} ->
|
||||
{error, timeout};
|
||||
{_Ref, Wat} ->
|
||||
lager:info("got a wat ~p", [Wat]),
|
||||
stream_loop(Acc)
|
||||
|
60
tests/verify_2i_timeout.erl
Normal file
60
tests/verify_2i_timeout.erl
Normal file
@ -0,0 +1,60 @@
|
||||
%% -------------------------------------------------------------------
|
||||
%%
|
||||
%% Copyright (c) 2013 Basho Technologies, Inc.
|
||||
%%
|
||||
%% This file is provided to you under the Apache License,
|
||||
%% Version 2.0 (the "License"); you may not use this file
|
||||
%% except in compliance with the License. You may obtain
|
||||
%% a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing,
|
||||
%% software distributed under the License is distributed on an
|
||||
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
%% KIND, either express or implied. See the License for the
|
||||
%% specific language governing permissions and limitations
|
||||
%% under the License.
|
||||
%%
|
||||
%% -------------------------------------------------------------------
|
||||
-module(verify_2i_timeout).
|
||||
-behavior(riak_test).
|
||||
-export([confirm/0]).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-import(secondary_index_tests, [put_an_object/2, put_an_object/4, int_to_key/1,
|
||||
stream_pb/3, url/2, http_query/3]).
|
||||
-define(BUCKET, <<"2ibucket">>).
|
||||
-define(FOO, <<"foo">>).
|
||||
|
||||
confirm() ->
|
||||
inets:start(),
|
||||
Config = [{riak_kv, [{secondary_index_timeout, 1}]}], %% ludicrously short, should fail always
|
||||
Nodes = rt:build_cluster([{current, Config}, {current, Config}, {current, Config}]),
|
||||
?assertEqual(ok, (rt:wait_until_nodes_ready(Nodes))),
|
||||
|
||||
PBPid = rt:pbc(hd(Nodes)),
|
||||
Http = rt:http_url(hd(Nodes)),
|
||||
|
||||
[put_an_object(PBPid, N) || N <- lists:seq(0, 100)],
|
||||
[put_an_object(PBPid, int_to_key(N), N, ?FOO) || N <- lists:seq(101, 200)],
|
||||
|
||||
ExpectedKeys = lists:sort([int_to_key(N) || N <- lists:seq(0, 200)]),
|
||||
Query = {<<"$bucket">>, ?BUCKET},
|
||||
%% Verifies that the app.config param was used
|
||||
?assertEqual({error, timeout}, stream_pb(PBPid, Query, [])),
|
||||
|
||||
%% Override app.config
|
||||
{ok, Res} = stream_pb(PBPid, Query, [{timeout, 5000}]),
|
||||
?assertEqual(ExpectedKeys, proplists:get_value(keys, Res, [])),
|
||||
|
||||
{ok, {{_, 500, _}, _, Body}} = httpc:request(url("~s/buckets/~s/index/~s/~s~s",
|
||||
[Http, ?BUCKET, <<"$bucket">>, ?BUCKET, []])),
|
||||
?assertMatch({match, _}, re:run(Body, "{error,timeout}")), %% shows the app.config timeout
|
||||
|
||||
HttpRes = http_query(Http, Query, [{timeout, 5000}]),
|
||||
?assertEqual(ExpectedKeys, proplists:get_value(<<"keys">>, HttpRes, [])),
|
||||
|
||||
riakc_pb_socket:stop(PBPid),
|
||||
pass.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user