Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Feb 29, 2024
1 parent a3a8819 commit 4ad009f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions big_tests/tests/mod_event_pusher_rabbit_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
-define(CHAT_MSG_RECV_TOPIC, <<"custom_chat_msg_recv_topic">>).
-define(GROUP_CHAT_MSG_SENT_TOPIC, <<"custom_group_chat_msg_sent_topic">>).
-define(GROUP_CHAT_MSG_RECV_TOPIC, <<"custom_group_chat_msg_recv_topic">>).
-define(WPOOL_CFG, #{scope => host_type,
-define(WPOOL_CFG, #{tag => event_pusher, scope => host_type,
opts => #{workers => 20, strategy => best_worker, call_timeout => 5000}}).
-define(IF_EXCHANGE_EXISTS_RETRIES, 30).
-define(WAIT_FOR_EXCHANGE_INTERVAL, 100). % ms
Expand Down Expand Up @@ -614,7 +614,7 @@ start_rabbit_wpool(Host) ->

start_rabbit_wpool(Host, WpoolConfig) ->
rpc(mim(), mongoose_wpool, ensure_started, []),
Pool = config([outgoing_pools, rabbit, event_pusher], WpoolConfig),
Pool = config([outgoing_pools, rabbit], WpoolConfig),
[{ok, _Pid}] = rpc(mim(), mongoose_wpool, start_configured_pools, [[Pool], [Host]]).

stop_rabbit_wpool({Pool, Host, Tag}) ->
Expand Down
4 changes: 2 additions & 2 deletions big_tests/tests/push_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ check_default_format(From, To, Body, Msg) ->
start_pool() ->
PoolOpts = #{strategy => random_worker, call_timeout => 5000, workers => 10},
ConnOpts = #{host => http_notifications_host(), request_timeout => 5000},
Pool = config([outgoing_pools, http, http_pool],
#{scope => host_type, opts => PoolOpts, conn_opts => ConnOpts}),
Pool = config([outgoing_pools, http],
#{tag => http_pool, scope => host_type, opts => PoolOpts, conn_opts => ConnOpts}),
[{ok, _Pid}] = rpc(mongoose_wpool, start_configured_pools, [[Pool], [<<"localhost">>]]).

stop_pool() ->
Expand Down
1 change: 1 addition & 0 deletions src/config/mongoose_config_spec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ outgoing_pools() ->
|| PoolType <- PoolTypes]),
#section{
items = Items,
process = fun mongoose_wpool:verify_unique_pools/1,
wrap = global_config,
format_items = list
}.
Expand Down
21 changes: 21 additions & 0 deletions src/wpool/mongoose_wpool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
-export([is_configured/1]).
-export([make_pool_name/3]).
-export([call_start_callback/2]).
-export([verify_unique_pools/1]).

%% Mostly for tests
-export([expand_pools/2]).
Expand Down Expand Up @@ -89,6 +90,26 @@

-optional_callbacks([is_supported_strategy/1]).

%% @doc Verify that all outgoing_pools have unique type, tag and scope
-spec verify_unique_pools([pool_map_in()]) -> [pool_map()].
verify_unique_pools(Pools) ->
PoolKeys = lists:map(fun pool_id/1, Pools),
case {lists:usort(PoolKeys), lists:sort(PoolKeys)} of
{SortedPool, SortedPool} -> Pools;
{Uniques, ContainsDuplicates} ->
Dups = lists:subtract(ContainsDuplicates, Uniques),
error(#{what => duplicate_pools, duplicates => Dups,

Check warning on line 101 in src/wpool/mongoose_wpool.erl

View check run for this annotation

Codecov / codecov/patch

src/wpool/mongoose_wpool.erl#L100-L101

Added lines #L100 - L101 were not covered by tests
text => <<"Some pools are duplicated">>})
end.


%% @doc Create a unique ID based on the configuration identifiers
-spec pool_id(pool_map_in()) -> {scope(), pool_type(), tag()}.
pool_id(#{scope := HostType, type := Type, tag := Tag}) when is_binary(HostType) ->
{host_type, Type, Tag};

Check warning on line 109 in src/wpool/mongoose_wpool.erl

View check run for this annotation

Codecov / codecov/patch

src/wpool/mongoose_wpool.erl#L109

Added line #L109 was not covered by tests
pool_id(#{scope := Scope, type := Type, tag := Tag}) ->
{Scope, Type, Tag}.

ensure_started() ->
wpool:start(),
case whereis(mongoose_wpool_sup) of
Expand Down
2 changes: 1 addition & 1 deletion test/common/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ default_pool_wpool_opts(_) ->
default_wpool_opts().

default_wpool_opts() ->
#{workers => 10,
#{workers => 10,
strategy => best_worker,
call_timeout => 5000}.

Expand Down

0 comments on commit 4ad009f

Please sign in to comment.