chore: to_integer to make sure integer is converted

This commit is contained in:
zhongwencool 2023-06-19 16:30:18 +08:00
parent 07172e42f0
commit 093cdab838
3 changed files with 24 additions and 9 deletions

View File

@ -2418,13 +2418,13 @@ mk_duration(Desc, OverrideMeta) ->
to_duration(Str) ->
case hocon_postprocess:duration(Str) of
I when is_integer(I) -> {ok, I};
_ -> {error, Str}
_ -> to_integer(Str)
end.
to_duration_s(Str) ->
case hocon_postprocess:duration(Str) of
I when is_number(I) -> {ok, ceiling(I / 1000)};
_ -> {error, Str}
_ -> to_integer(Str)
end.
-spec to_duration_ms(Input) -> {ok, integer()} | {error, Input} when
@ -2432,7 +2432,7 @@ to_duration_s(Str) ->
to_duration_ms(Str) ->
case hocon_postprocess:duration(Str) of
I when is_number(I) -> {ok, ceiling(I)};
_ -> {error, Str}
_ -> to_integer(Str)
end.
-spec to_timeout_duration(Input) -> {ok, timeout_duration()} | {error, Input} when
@ -2473,7 +2473,7 @@ do_to_timeout_duration(Str, Fn, Max, Unit) ->
to_bytesize(Str) ->
case hocon_postprocess:bytesize(Str) of
I when is_integer(I) -> {ok, I};
_ -> {error, Str}
_ -> to_integer(Str)
end.
to_wordsize(Str) ->
@ -2483,6 +2483,13 @@ to_wordsize(Str) ->
Error -> Error
end.
to_integer(Str) when is_list(Str) ->
case string:to_integer(Str) of
{Int, []} -> {ok, Int};
{Int, <<>>} -> {ok, Int};
_ -> {error, Str}
end.
to_percent(Str) ->
{ok, hocon_postprocess:percent(Str)}.

View File

@ -144,8 +144,12 @@ init_per_testcase(t_ocsp_responder_error_responses, Config) ->
},
Conf = #{listeners => #{Type => #{Name => ListenerOpts}}},
ConfBin = emqx_utils_maps:binary_key_map(Conf),
hocon_tconf:check_plain(emqx_schema, ConfBin, #{required => false, atom_keys => false}),
emqx_config:put_listener_conf(Type, Name, [], ListenerOpts),
CheckedConf = hocon_tconf:check_plain(emqx_schema, ConfBin, #{
required => false, atom_keys => false
}),
Conf2 = emqx_utils_maps:unsafe_atom_key_map(CheckedConf),
ListenerOpts2 = emqx_utils_maps:deep_get([listeners, Type, Name], Conf2),
emqx_config:put_listener_conf(Type, Name, [], ListenerOpts2),
snabbkaffe:start_trace(),
_Heir = spawn_dummy_heir(),
{ok, CachePid} = emqx_ocsp_cache:start_link(),
@ -186,8 +190,12 @@ init_per_testcase(_TestCase, Config) ->
},
Conf = #{listeners => #{Type => #{Name => ListenerOpts}}},
ConfBin = emqx_utils_maps:binary_key_map(Conf),
hocon_tconf:check_plain(emqx_schema, ConfBin, #{required => false, atom_keys => false}),
emqx_config:put_listener_conf(Type, Name, [], ListenerOpts),
CheckedConf = hocon_tconf:check_plain(emqx_schema, ConfBin, #{
required => false, atom_keys => false
}),
Conf2 = emqx_utils_maps:unsafe_atom_key_map(CheckedConf),
ListenerOpts2 = emqx_utils_maps:deep_get([listeners, Type, Name], Conf2),
emqx_config:put_listener_conf(Type, Name, [], ListenerOpts2),
[
{cache_pid, CachePid}
| Config

View File

@ -178,7 +178,7 @@ bridge_async_config(#{port := Port} = Config) ->
Name = maps:get(name, Config, ?BRIDGE_NAME),
PoolSize = maps:get(pool_size, Config, 1),
QueryMode = maps:get(query_mode, Config, "async"),
ConnectTimeout = maps:get(connect_timeout, Config, 1),
ConnectTimeout = maps:get(connect_timeout, Config, "1s"),
RequestTimeout = maps:get(request_timeout, Config, "10s"),
ResumeInterval = maps:get(resume_interval, Config, "1s"),
ResourceRequestTTL = maps:get(resource_request_ttl, Config, "infinity"),