fix(test): update test cases for emqx_resource:health_check/1
This commit is contained in:
parent
1054c364ad
commit
d37a66e9b8
|
@ -83,7 +83,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
|
|||
status := InitialStatus
|
||||
}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(ok, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({ok, connected}, emqx_resource:health_check(PoolName)),
|
||||
% % Perform query as further check that the resource is working as expected
|
||||
?assertMatch([], emqx_resource:query(PoolName, test_query_find())),
|
||||
?assertMatch(undefined, emqx_resource:query(PoolName, test_query_find_one())),
|
||||
|
@ -96,7 +96,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
|
|||
}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(StoppedStatus, disconnected),
|
||||
?assertEqual({error, stopped}, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({error, resource_is_stopped}, emqx_resource:health_check(PoolName)),
|
||||
% Resource healthcheck shortcuts things by checking ets. Go deeper by checking pool itself.
|
||||
?assertEqual({error, not_found}, ecpool:stop_sup_pool(ReturnedPoolName)),
|
||||
% Can call stop/1 again on an already stopped instance
|
||||
|
@ -107,7 +107,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
|
|||
timer:sleep(500),
|
||||
{ok, ?CONNECTOR_RESOURCE_GROUP, #{status := InitialStatus}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(ok, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({ok, connected}, emqx_resource:health_check(PoolName)),
|
||||
?assertMatch([], emqx_resource:query(PoolName, test_query_find())),
|
||||
?assertMatch(undefined, emqx_resource:query(PoolName, test_query_find_one())),
|
||||
% Stop and remove the resource in one go.
|
||||
|
|
|
@ -82,7 +82,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
|
|||
status := InitialStatus
|
||||
}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(ok, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({ok, connected}, emqx_resource:health_check(PoolName)),
|
||||
% % Perform query as further check that the resource is working as expected
|
||||
?assertMatch({ok, _, [[1]]}, emqx_resource:query(PoolName, test_query_no_params())),
|
||||
?assertMatch({ok, _, [[1]]}, emqx_resource:query(PoolName, test_query_with_params())),
|
||||
|
@ -102,7 +102,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
|
|||
}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(StoppedStatus, disconnected),
|
||||
?assertEqual({error, stopped}, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({error, resource_is_stopped}, emqx_resource:health_check(PoolName)),
|
||||
% Resource healthcheck shortcuts things by checking ets. Go deeper by checking pool itself.
|
||||
?assertEqual({error, not_found}, ecpool:stop_sup_pool(ReturnedPoolName)),
|
||||
% Can call stop/1 again on an already stopped instance
|
||||
|
@ -113,7 +113,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
|
|||
timer:sleep(500),
|
||||
{ok, ?CONNECTOR_RESOURCE_GROUP, #{status := InitialStatus}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(ok, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({ok, connected}, emqx_resource:health_check(PoolName)),
|
||||
?assertMatch({ok, _, [[1]]}, emqx_resource:query(PoolName, test_query_no_params())),
|
||||
?assertMatch({ok, _, [[1]]}, emqx_resource:query(PoolName, test_query_with_params())),
|
||||
?assertMatch(
|
||||
|
|
|
@ -83,7 +83,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
|
|||
status := InitialStatus
|
||||
}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(ok, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({ok, connected}, emqx_resource:health_check(PoolName)),
|
||||
% % Perform query as further check that the resource is working as expected
|
||||
?assertMatch({ok, _, [{1}]}, emqx_resource:query(PoolName, test_query_no_params())),
|
||||
?assertMatch({ok, _, [{1}]}, emqx_resource:query(PoolName, test_query_with_params())),
|
||||
|
@ -96,7 +96,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
|
|||
}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(StoppedStatus, disconnected),
|
||||
?assertEqual({error, stopped}, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({error, resource_is_stopped}, emqx_resource:health_check(PoolName)),
|
||||
% Resource healthcheck shortcuts things by checking ets. Go deeper by checking pool itself.
|
||||
?assertEqual({error, not_found}, ecpool:stop_sup_pool(ReturnedPoolName)),
|
||||
% Can call stop/1 again on an already stopped instance
|
||||
|
@ -107,7 +107,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
|
|||
timer:sleep(500),
|
||||
{ok, ?CONNECTOR_RESOURCE_GROUP, #{status := InitialStatus}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(ok, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({ok, connected}, emqx_resource:health_check(PoolName)),
|
||||
?assertMatch({ok, _, [{1}]}, emqx_resource:query(PoolName, test_query_no_params())),
|
||||
?assertMatch({ok, _, [{1}]}, emqx_resource:query(PoolName, test_query_with_params())),
|
||||
% Stop and remove the resource in one go.
|
||||
|
|
|
@ -97,7 +97,7 @@ perform_lifecycle_check(PoolName, InitialConfig, RedisCommand) ->
|
|||
status := InitialStatus
|
||||
}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(ok, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({ok, connected}, emqx_resource:health_check(PoolName)),
|
||||
% Perform query as further check that the resource is working as expected
|
||||
?assertEqual({ok, <<"PONG">>}, emqx_resource:query(PoolName, {cmd, RedisCommand})),
|
||||
?assertEqual(ok, emqx_resource:stop(PoolName)),
|
||||
|
@ -109,7 +109,7 @@ perform_lifecycle_check(PoolName, InitialConfig, RedisCommand) ->
|
|||
}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(StoppedStatus, disconnected),
|
||||
?assertEqual({error, stopped}, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({error, resource_is_stopped}, emqx_resource:health_check(PoolName)),
|
||||
% Resource healthcheck shortcuts things by checking ets. Go deeper by checking pool itself.
|
||||
?assertEqual({error, not_found}, ecpool:stop_sup_pool(ReturnedPoolName)),
|
||||
% Can call stop/1 again on an already stopped instance
|
||||
|
@ -120,7 +120,7 @@ perform_lifecycle_check(PoolName, InitialConfig, RedisCommand) ->
|
|||
timer:sleep(500),
|
||||
{ok, ?CONNECTOR_RESOURCE_GROUP, #{status := InitialStatus}} =
|
||||
emqx_resource:get_instance(PoolName),
|
||||
?assertEqual(ok, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({ok, connected}, emqx_resource:health_check(PoolName)),
|
||||
?assertEqual({ok, <<"PONG">>}, emqx_resource:query(PoolName, {cmd, RedisCommand})),
|
||||
% Stop and remove the resource in one go.
|
||||
?assertEqual(ok, emqx_resource:remove_local(PoolName)),
|
||||
|
|
|
@ -276,7 +276,7 @@ restart(InstId, Opts) ->
|
|||
stop(InstId) ->
|
||||
emqx_resource_manager:stop(InstId).
|
||||
|
||||
-spec health_check(instance_id()) -> resource_status().
|
||||
-spec health_check(instance_id()) -> {ok, resource_status()} | {error, term()}.
|
||||
health_check(InstId) ->
|
||||
emqx_resource_manager:health_check(InstId).
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ list_group(Group) ->
|
|||
List = ets:match(?ETS_TABLE, {'$1', Group, '_'}),
|
||||
lists:flatten(List).
|
||||
|
||||
-spec health_check(instance_id()) -> resource_status().
|
||||
-spec health_check(instance_id()) -> {ok, resource_status()} | {error, term()}.
|
||||
health_check(InstId) ->
|
||||
safe_call(InstId, health_check).
|
||||
|
||||
|
@ -351,7 +351,7 @@ proc_name(Id) ->
|
|||
|
||||
handle_health_check_request(From, Data) ->
|
||||
with_health_check(Data, fun(Status, UpdatedData) ->
|
||||
Actions = [{reply, From, Status}],
|
||||
Actions = [{reply, From, {ok, Status}}],
|
||||
{next_state, Status, UpdatedData, Actions}
|
||||
end).
|
||||
|
||||
|
|
|
@ -182,7 +182,7 @@ t_healthy(_) ->
|
|||
timer:sleep(300),
|
||||
emqx_resource:set_resource_status_connecting(?ID),
|
||||
|
||||
ok = emqx_resource:health_check(?ID),
|
||||
{ok, connected} = emqx_resource:health_check(?ID),
|
||||
|
||||
?assertMatch(
|
||||
[#{status := connected}],
|
||||
|
@ -191,7 +191,7 @@ t_healthy(_) ->
|
|||
|
||||
erlang:exit(Pid, shutdown),
|
||||
|
||||
?assertEqual({error, connecting}, emqx_resource:health_check(?ID)),
|
||||
?assertEqual({ok, connecting}, emqx_resource:health_check(?ID)),
|
||||
|
||||
?assertMatch(
|
||||
[],
|
||||
|
@ -368,7 +368,7 @@ t_auto_retry(_) ->
|
|||
#{name => test_resource, create_error => true},
|
||||
#{auto_retry_interval => 100}
|
||||
),
|
||||
?assertEqual(error, Res).
|
||||
?assertEqual(ok, Res).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Helpers
|
||||
|
|
Loading…
Reference in New Issue