fix(sysk): fix probe testing bugs for syskeeper
This commit is contained in:
parent
59c5e3c16f
commit
cd90b93550
|
@ -67,11 +67,17 @@ on_start(
|
||||||
{tcp_options, [{mode, binary}, {reuseaddr, true}, {nodelay, true}]}
|
{tcp_options, [{mode, binary}, {reuseaddr, true}, {nodelay, true}]}
|
||||||
],
|
],
|
||||||
MFArgs = {?MODULE, start_link, [maps:with([handshake_timeout], Config)]},
|
MFArgs = {?MODULE, start_link, [maps:with([handshake_timeout], Config)]},
|
||||||
ok = emqx_resource:allocate_resource(InstanceId, listen_on, ListenOn),
|
|
||||||
|
|
||||||
|
%% Since the esockd only supports atomic name and we don't want to introduce a new atom per each instance
|
||||||
|
%% when the port is same for two instance/connector, them will reference to a same esockd listener
|
||||||
|
%% to prevent the failed one dealloctes the listener which created by a earlier instance
|
||||||
|
%% we need record only when the listen is successed
|
||||||
case esockd:open(?MODULE, ListenOn, Options, MFArgs) of
|
case esockd:open(?MODULE, ListenOn, Options, MFArgs) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
|
ok = emqx_resource:allocate_resource(InstanceId, listen_on, ListenOn),
|
||||||
{ok, #{listen_on => ListenOn}};
|
{ok, #{listen_on => ListenOn}};
|
||||||
|
{error, {already_started, _}} ->
|
||||||
|
{error, eaddrinuse};
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
@ -83,7 +89,12 @@ on_stop(InstanceId, _State) ->
|
||||||
}),
|
}),
|
||||||
case emqx_resource:get_allocated_resources(InstanceId) of
|
case emqx_resource:get_allocated_resources(InstanceId) of
|
||||||
#{listen_on := ListenOn} ->
|
#{listen_on := ListenOn} ->
|
||||||
esockd:close(?MODULE, ListenOn);
|
case esockd:close(?MODULE, ListenOn) of
|
||||||
|
{error, not_found} ->
|
||||||
|
ok;
|
||||||
|
Result ->
|
||||||
|
Result
|
||||||
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -229,7 +229,10 @@ create_dry_run(Type, Conf0, Callback) ->
|
||||||
TypeBin = bin(Type),
|
TypeBin = bin(Type),
|
||||||
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
|
||||||
TmpName = iolist_to_binary([?TEST_ID_PREFIX, TypeBin, ":", <<"probedryrun">>]),
|
%% to avoid potential race condition, the resource id should be unique
|
||||||
|
UID = integer_to_binary(erlang:unique_integer([monotonic, positive])),
|
||||||
|
TmpName =
|
||||||
|
iolist_to_binary([?TEST_ID_PREFIX, TypeBin, ":", <<"probedryrun">>, UID]),
|
||||||
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}}},
|
||||||
|
|
Loading…
Reference in New Issue