Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow any term to be a coordinator name #183

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/coordinator/amoc_coordinator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
-define(IS_N_OF_USERS(N), (?IS_POS_INT(N) orelse N =:= all)).
-define(IS_TIMEOUT(Timeout), (?IS_POS_INT(Timeout) orelse Timeout =:= infinity)).

-type name() :: atom().
-type name() :: term().

-type data() :: {pid(), Data :: any()}.

Expand Down Expand Up @@ -102,11 +102,11 @@ reset(Name) ->
notify(Name, reset_coordinator).

-spec notify(name(), coordinator_timeout | reset_coordinator | {coordinate, {pid(), term()}}) -> ok.
notify(Name, coordinator_timeout) when is_atom(Name) ->
notify(Name, coordinator_timeout) ->
do_notify(Name, coordinator_timeout);
notify(Name, reset_coordinator) when is_atom(Name) ->
notify(Name, reset_coordinator) ->
do_notify(Name, reset_coordinator);
notify(Name, {coordinate, _} = Event) when is_atom(Name) ->
notify(Name, {coordinate, _} = Event) ->
do_notify(Name, Event).

do_notify(Name, Event) ->
Expand Down
1 change: 0 additions & 1 deletion src/coordinator/amoc_coordinator_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ start_link() ->

-spec init(term()) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
init([]) ->
ets:new(?MODULE, [named_table, ordered_set, public, {read_concurrency, true}]),
AChild = #{id => amoc_coordinator_worker_sup,
start => {amoc_coordinator_worker_sup, start_link, []},
restart => transient,
Expand Down
12 changes: 12 additions & 0 deletions test/amoc_coordinator_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ all() ->
plan_normalises_successfully,
ordering_plan_sets_all_at_the_end,
failing_action_does_not_kill_the_worker,
coordinator_name_can_be_dynamic_terms,
execute_with_range_without_timeout,
execute_plan_without_timeout,
reset_plan_without_timeout,
Expand Down Expand Up @@ -220,6 +221,17 @@ execute_plan_with_timeout(_Config) ->
assert_telemetry_events(Name, [start, {N1, add}, timeout,
{N2, add}, timeout, stop]).

coordinator_name_can_be_dynamic_terms(_) ->
BinName = <<(atom_to_binary(?FUNCTION_NAME))/binary, (crypto:strong_rand_bytes(8))/binary>>,
SomePlan = [{1000, fun(_Event) -> ok end}],
Names = [{some_composed_tuple},
[list, made_of, atoms],
base64:encode(BinName)],
[ ?assertEqual(ok, amoc_coordinator:start(Name, SomePlan)) || Name <- Names ],
[ {ok, _, _Workers} = amoc_coordinator_sup:get_workers(Name) || Name <- Names ],
[ [amoc_coordinator:add(Name, User) || User <- lists:seq(1, 10)] || Name <- Names ],
[ amoc_coordinator:stop(Name) || Name <- Names ].

failing_action_does_not_kill_the_worker(_) ->
Name = ?FUNCTION_NAME,
Plan = {2, [mock_failing()]},
Expand Down
Loading