Skip to content

Commit

Permalink
wip verify pools are unique
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Feb 29, 2024
1 parent 7bd5f05 commit 3a4cab7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 3a4cab7

Please sign in to comment.