fix(connector): make the connector id unique when doing probe testing

This commit is contained in:
firest 2024-01-23 13:03:12 +08:00
parent cd90b93550
commit 51e8c955ff
2 changed files with 5 additions and 4 deletions

View File

@ -107,7 +107,7 @@ parse_connector_id(ConnectorId) ->
{atom(), atom() | binary()}. {atom(), atom() | binary()}.
parse_connector_id(<<"connector:", ConnectorId/binary>>, Opts) -> parse_connector_id(<<"connector:", ConnectorId/binary>>, Opts) ->
parse_connector_id(ConnectorId, Opts); parse_connector_id(ConnectorId, Opts);
parse_connector_id(<<?TEST_ID_PREFIX, ConnectorId/binary>>, Opts) -> parse_connector_id(<<?TEST_ID_PREFIX, _:16/binary, ConnectorId/binary>>, Opts) ->
parse_connector_id(ConnectorId, Opts); parse_connector_id(ConnectorId, Opts);
parse_connector_id(ConnectorId, Opts) -> parse_connector_id(ConnectorId, Opts) ->
emqx_resource:parse_resource_id(ConnectorId, Opts). emqx_resource:parse_resource_id(ConnectorId, Opts).
@ -230,9 +230,9 @@ create_dry_run(Type, Conf0, Callback) ->
TypeAtom = safe_atom(Type), TypeAtom = safe_atom(Type),
%% We use a fixed name here to avoid creating an atom %% We use a fixed name here to avoid creating an atom
%% to avoid potential race condition, the resource id should be unique %% to avoid potential race condition, the resource id should be unique
UID = integer_to_binary(erlang:unique_integer([monotonic, positive])), Prefix = emqx_resource_manager:make_test_id(),
TmpName = TmpName =
iolist_to_binary([?TEST_ID_PREFIX, TypeBin, ":", <<"probedryrun">>, UID]), iolist_to_binary([Prefix, TypeBin, ":", <<"probedryrun">>]),
TmpPath = emqx_utils:safe_filename(TmpName), TmpPath = emqx_utils:safe_filename(TmpName),
Conf1 = maps:without([<<"name">>], Conf0), Conf1 = maps:without([<<"name">>], Conf0),
RawConf = #{<<"connectors">> => #{TypeBin => #{<<"temp_name">> => Conf1}}}, RawConf = #{<<"connectors">> => #{TypeBin => #{<<"temp_name">> => Conf1}}},

View File

@ -50,7 +50,8 @@
]). ]).
-export([ -export([
set_resource_status_connecting/1 set_resource_status_connecting/1,
make_test_id/0
]). ]).
% Server % Server