fix(redis): set bridge as unhealthy on authentication error
This commit is contained in:
parent
fc35c74eab
commit
05fdf52d8e
|
@ -35,6 +35,12 @@ on_start(InstId, #{command_template := CommandTemplate} = Config) ->
|
||||||
conn_st => RedisConnSt,
|
conn_st => RedisConnSt,
|
||||||
command_template => preproc_command_template(CommandTemplate)
|
command_template => preproc_command_template(CommandTemplate)
|
||||||
}};
|
}};
|
||||||
|
{error, {start_pool_failed, _, #{type := authentication_error, reason := Reason}}} = Error ->
|
||||||
|
?tp(
|
||||||
|
redis_bridge_connector_start_error,
|
||||||
|
#{error => Error}
|
||||||
|
),
|
||||||
|
throw({unhealthy_target, Reason});
|
||||||
{error, _} = Error ->
|
{error, _} = Error ->
|
||||||
?tp(
|
?tp(
|
||||||
redis_bridge_connector_start_error,
|
redis_bridge_connector_start_error,
|
||||||
|
|
|
@ -340,6 +340,47 @@ t_auth_username_password(_Config) ->
|
||||||
),
|
),
|
||||||
{ok, _} = emqx_bridge:remove(Type, Name).
|
{ok, _} = emqx_bridge:remove(Type, Name).
|
||||||
|
|
||||||
|
t_auth_error_username_password(_Config) ->
|
||||||
|
Name = <<"mybridge">>,
|
||||||
|
Type = <<"redis_single">>,
|
||||||
|
ResourceId = emqx_bridge_resource:resource_id(Type, Name),
|
||||||
|
BridgeConfig0 = username_password_redis_bridge_config(),
|
||||||
|
BridgeConfig = maps:merge(BridgeConfig0, #{<<"password">> => <<"wrong_password">>}),
|
||||||
|
?assertMatch(
|
||||||
|
{ok, _},
|
||||||
|
emqx_bridge:create(Type, Name, BridgeConfig)
|
||||||
|
),
|
||||||
|
?WAIT(
|
||||||
|
{ok, disconnected},
|
||||||
|
emqx_resource:health_check(ResourceId),
|
||||||
|
5
|
||||||
|
),
|
||||||
|
?assertMatch(
|
||||||
|
{ok, _, #{error := {unhealthy_target, _Msg}}},
|
||||||
|
emqx_resource_manager:lookup(ResourceId)
|
||||||
|
),
|
||||||
|
{ok, _} = emqx_bridge:remove(Type, Name).
|
||||||
|
|
||||||
|
t_auth_error_password_only(_Config) ->
|
||||||
|
Name = <<"mybridge">>,
|
||||||
|
Type = <<"redis_single">>,
|
||||||
|
ResourceId = emqx_bridge_resource:resource_id(Type, Name),
|
||||||
|
BridgeConfig0 = toxiproxy_redis_bridge_config(),
|
||||||
|
BridgeConfig = maps:merge(BridgeConfig0, #{<<"password">> => <<"wrong_password">>}),
|
||||||
|
?assertMatch(
|
||||||
|
{ok, _},
|
||||||
|
emqx_bridge:create(Type, Name, BridgeConfig)
|
||||||
|
),
|
||||||
|
?assertEqual(
|
||||||
|
{ok, disconnected},
|
||||||
|
emqx_resource:health_check(ResourceId)
|
||||||
|
),
|
||||||
|
?assertMatch(
|
||||||
|
{ok, _, #{error := {unhealthy_target, _Msg}}},
|
||||||
|
emqx_resource_manager:lookup(ResourceId)
|
||||||
|
),
|
||||||
|
{ok, _} = emqx_bridge:remove(Type, Name).
|
||||||
|
|
||||||
t_create_disconnected(Config) ->
|
t_create_disconnected(Config) ->
|
||||||
Name = <<"toxic_bridge">>,
|
Name = <<"toxic_bridge">>,
|
||||||
Type = <<"redis_single">>,
|
Type = <<"redis_single">>,
|
||||||
|
|
Loading…
Reference in New Issue