Merge pull request #9628 from savonarola/fix-flaky-redis-bridge-test

chore(ee bridge): fix Redis bridge test flakyness
This commit is contained in:
Ilya Averyanov 2023-01-18 20:56:13 +02:00 committed by GitHub
commit f9843de7ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 46 deletions

View File

@ -52,7 +52,7 @@ down:
down --remove-orphans down --remove-orphans
ct: ct:
docker exec -i "$(CONTAINER)" bash -c "rebar3 ct --name 'test@127.0.0.1' -v --suite $(SUITE)" docker exec -i "$(CONTAINER)" bash -c "rebar3 ct --name 'test@127.0.0.1' --readable true -v --suite $(SUITE)"
ct-all: ct-all:
docker exec -i "$(CONTAINER)" bash -c "make ct" docker exec -i "$(CONTAINER)" bash -c "make ct"

View File

@ -101,6 +101,14 @@
-define(HEALTHCHECK_INTERVAL, 15000). -define(HEALTHCHECK_INTERVAL, 15000).
-define(HEALTHCHECK_INTERVAL_RAW, <<"15s">>). -define(HEALTHCHECK_INTERVAL_RAW, <<"15s">>).
%% milliseconds
-define(START_TIMEOUT, 5000).
-define(START_TIMEOUT_RAW, <<"5s">>).
%% boolean
-define(START_AFTER_CREATED, true).
-define(START_AFTER_CREATED_RAW, <<"true">>).
%% milliseconds %% milliseconds
-define(AUTO_RESTART_INTERVAL, 60000). -define(AUTO_RESTART_INTERVAL, 60000).
-define(AUTO_RESTART_INTERVAL_RAW, <<"60s">>). -define(AUTO_RESTART_INTERVAL_RAW, <<"60s">>).

View File

@ -116,11 +116,6 @@ create_and_return_data(MgrId, ResId, Group, ResourceType, Config, Opts) ->
{ok, _Group, Data} = lookup(ResId), {ok, _Group, Data} = lookup(ResId),
{ok, Data}. {ok, Data}.
%% internal configs
-define(START_AFTER_CREATED, true).
%% in milliseconds
-define(START_TIMEOUT, 5000).
%% @doc Create a resource_manager and wait until it is running %% @doc Create a resource_manager and wait until it is running
create(MgrId, ResId, Group, ResourceType, Config, Opts) -> create(MgrId, ResId, Group, ResourceType, Config, Opts) ->
% The state machine will make the actual call to the callback/resource module after init % The state machine will make the actual call to the callback/resource module after init

View File

@ -46,6 +46,8 @@ fields("creation_opts") ->
[ [
{worker_pool_size, fun worker_pool_size/1}, {worker_pool_size, fun worker_pool_size/1},
{health_check_interval, fun health_check_interval/1}, {health_check_interval, fun health_check_interval/1},
{start_after_created, fun start_after_created/1},
{start_timeout, fun start_timeout/1},
{auto_restart_interval, fun auto_restart_interval/1}, {auto_restart_interval, fun auto_restart_interval/1},
{query_mode, fun query_mode/1}, {query_mode, fun query_mode/1},
{request_timeout, fun request_timeout/1}, {request_timeout, fun request_timeout/1},
@ -69,6 +71,18 @@ health_check_interval(default) -> ?HEALTHCHECK_INTERVAL_RAW;
health_check_interval(required) -> false; health_check_interval(required) -> false;
health_check_interval(_) -> undefined. health_check_interval(_) -> undefined.
start_after_created(type) -> boolean();
start_after_created(desc) -> ?DESC("start_after_created");
start_after_created(default) -> ?START_AFTER_CREATED_RAW;
start_after_created(required) -> false;
start_after_created(_) -> undefined.
start_timeout(type) -> emqx_schema:duration_ms();
start_timeout(desc) -> ?DESC("start_timeout");
start_timeout(default) -> ?START_TIMEOUT_RAW;
start_timeout(required) -> false;
start_timeout(_) -> undefined.
auto_restart_interval(type) -> hoconsc:union([infinity, emqx_schema:duration_ms()]); auto_restart_interval(type) -> hoconsc:union([infinity, emqx_schema:duration_ms()]);
auto_restart_interval(desc) -> ?DESC("auto_restart_interval"); auto_restart_interval(desc) -> ?DESC("auto_restart_interval");
auto_restart_interval(default) -> ?AUTO_RESTART_INTERVAL_RAW; auto_restart_interval(default) -> ?AUTO_RESTART_INTERVAL_RAW;

View File

@ -0,0 +1 @@
Expose additional resource configuration parameters: `start_after_created` and `start_timeout`.

View File

@ -0,0 +1 @@
为桥接资源增加了配置参数:`start_after_created` 和 `start_timeout`

View File

@ -137,6 +137,7 @@ end_per_suite(_Config) ->
ok. ok.
init_per_testcase(_Testcase, Config) -> init_per_testcase(_Testcase, Config) ->
ok = delete_all_rules(),
ok = delete_all_bridges(), ok = delete_all_bridges(),
case ?config(transport_type, Config) of case ?config(transport_type, Config) of
undefined -> undefined ->
@ -248,7 +249,6 @@ t_check_replay(Config) ->
), ),
?check_trace( ?check_trace(
begin
?wait_async_action( ?wait_async_action(
with_down_failure(Config, ProxyName, fun() -> with_down_failure(Config, ProxyName, fun() ->
{_, {ok, _}} = {_, {ok, _}} =
@ -269,8 +269,7 @@ t_check_replay(Config) ->
end), end),
#{?snk_kind := redis_ee_connector_send_done, batch := true, result := {ok, _}}, #{?snk_kind := redis_ee_connector_send_done, batch := true, result := {ok, _}},
10_000 10_000
) ),
end,
fun(Trace) -> fun(Trace) ->
?assert( ?assert(
?strict_causality( ?strict_causality(
@ -340,7 +339,7 @@ with_down_failure(Config, Name, F) ->
ProxyHost = ?config(proxy_host, Config), ProxyHost = ?config(proxy_host, Config),
emqx_common_test_helpers:with_failure(down, Name, ProxyHost, ProxyPort, F). emqx_common_test_helpers:with_failure(down, Name, ProxyHost, ProxyPort, F).
check_resource_queries(ResourceId, Topic, IsBatch) -> check_resource_queries(ResourceId, BaseTopic, IsBatch) ->
RandomPayload = rand:bytes(20), RandomPayload = rand:bytes(20),
N = N =
case IsBatch of case IsBatch of
@ -348,18 +347,18 @@ check_resource_queries(ResourceId, Topic, IsBatch) ->
false -> 1 false -> 1
end, end,
?check_trace( ?check_trace(
begin
?wait_async_action( ?wait_async_action(
lists:foreach( lists:foreach(
fun(_) -> fun(I) ->
IBin = integer_to_binary(I),
Topic = <<BaseTopic/binary, "/", IBin/binary>>,
_ = publish_message(Topic, RandomPayload) _ = publish_message(Topic, RandomPayload)
end, end,
lists:seq(1, N) lists:seq(1, N)
), ),
#{?snk_kind := redis_ee_connector_send_done, batch := IsBatch}, #{?snk_kind := redis_ee_connector_send_done, batch := IsBatch},
1000 5000
) ),
end,
fun(Trace) -> fun(Trace) ->
AddedMsgCount = length(added_msgs(ResourceId, RandomPayload)), AddedMsgCount = length(added_msgs(ResourceId, RandomPayload)),
case IsBatch of case IsBatch of
@ -394,6 +393,14 @@ conf_schema(StructName) ->
roots => [{root, hoconsc:ref(emqx_ee_bridge_redis, StructName)}] roots => [{root, hoconsc:ref(emqx_ee_bridge_redis, StructName)}]
}. }.
delete_all_rules() ->
lists:foreach(
fun(#{id := RuleId}) ->
emqx_rule_engine:delete_rule(RuleId)
end,
emqx_rule_engine:get_rules()
).
delete_all_bridges() -> delete_all_bridges() ->
lists:foreach( lists:foreach(
fun(#{name := Name, type := Type}) -> fun(#{name := Name, type := Type}) ->
@ -490,7 +497,8 @@ toxiproxy_redis_bridge_config() ->
<<"query_mode">> => <<"async">>, <<"query_mode">> => <<"async">>,
<<"worker_pool_size">> => <<"1">>, <<"worker_pool_size">> => <<"1">>,
<<"batch_size">> => integer_to_binary(?BATCH_SIZE), <<"batch_size">> => integer_to_binary(?BATCH_SIZE),
<<"health_check_interval">> => <<"1s">> <<"health_check_interval">> => <<"1s">>,
<<"start_timeout">> => <<"15s">>
} }
}, },
maps:merge(Conf0, ?COMMON_REDIS_OPTS). maps:merge(Conf0, ?COMMON_REDIS_OPTS).
@ -500,8 +508,10 @@ invalid_command_bridge_config() ->
Conf1 = maps:merge(Conf0, ?COMMON_REDIS_OPTS), Conf1 = maps:merge(Conf0, ?COMMON_REDIS_OPTS),
Conf1#{ Conf1#{
<<"resource_opts">> => #{ <<"resource_opts">> => #{
<<"query_mode">> => <<"sync">>,
<<"batch_size">> => <<"1">>, <<"batch_size">> => <<"1">>,
<<"worker_pool_size">> => <<"1">> <<"worker_pool_size">> => <<"1">>,
<<"start_timeout">> => <<"15s">>
}, },
<<"command_template">> => [<<"BAD">>, <<"COMMAND">>, <<"${payload}">>] <<"command_template">> => [<<"BAD">>, <<"COMMAND">>, <<"${payload}">>]
}. }.
@ -510,12 +520,14 @@ resource_configs() ->
#{ #{
batch_off => #{ batch_off => #{
<<"query_mode">> => <<"sync">>, <<"query_mode">> => <<"sync">>,
<<"batch_size">> => <<"1">> <<"batch_size">> => <<"1">>,
<<"start_timeout">> => <<"15s">>
}, },
batch_on => #{ batch_on => #{
<<"query_mode">> => <<"async">>, <<"query_mode">> => <<"async">>,
<<"worker_pool_size">> => <<"1">>, <<"worker_pool_size">> => <<"1">>,
<<"batch_size">> => integer_to_binary(?BATCH_SIZE) <<"batch_size">> => integer_to_binary(?BATCH_SIZE),
<<"start_timeout">> => <<"15s">>
} }
}. }.