Skip to content

Commit 887e312

Browse files
authored
Merge pull request #183 from esl/coordinator/arbitrary_names
Allow any term to be a coordinator name
2 parents 0d47028 + a89e5c1 commit 887e312

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/coordinator/amoc_coordinator.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
-define(IS_N_OF_USERS(N), (?IS_POS_INT(N) orelse N =:= all)).
2020
-define(IS_TIMEOUT(Timeout), (?IS_POS_INT(Timeout) orelse Timeout =:= infinity)).
2121

22-
-type name() :: atom().
22+
-type name() :: term().
2323

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

@@ -102,11 +102,11 @@ reset(Name) ->
102102
notify(Name, reset_coordinator).
103103

104104
-spec notify(name(), coordinator_timeout | reset_coordinator | {coordinate, {pid(), term()}}) -> ok.
105-
notify(Name, coordinator_timeout) when is_atom(Name) ->
105+
notify(Name, coordinator_timeout) ->
106106
do_notify(Name, coordinator_timeout);
107-
notify(Name, reset_coordinator) when is_atom(Name) ->
107+
notify(Name, reset_coordinator) ->
108108
do_notify(Name, reset_coordinator);
109-
notify(Name, {coordinate, _} = Event) when is_atom(Name) ->
109+
notify(Name, {coordinate, _} = Event) ->
110110
do_notify(Name, Event).
111111

112112
do_notify(Name, Event) ->

src/coordinator/amoc_coordinator_sup.erl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ start_link() ->
6868

6969
-spec init(term()) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
7070
init([]) ->
71-
ets:new(?MODULE, [named_table, ordered_set, public, {read_concurrency, true}]),
7271
AChild = #{id => amoc_coordinator_worker_sup,
7372
start => {amoc_coordinator_worker_sup, start_link, []},
7473
restart => transient,

test/amoc_coordinator_SUITE.erl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ all() ->
1414
plan_normalises_successfully,
1515
ordering_plan_sets_all_at_the_end,
1616
failing_action_does_not_kill_the_worker,
17+
coordinator_name_can_be_dynamic_terms,
1718
execute_with_range_without_timeout,
1819
execute_plan_without_timeout,
1920
reset_plan_without_timeout,
@@ -220,6 +221,17 @@ execute_plan_with_timeout(_Config) ->
220221
assert_telemetry_events(Name, [start, {N1, add}, timeout,
221222
{N2, add}, timeout, stop]).
222223

224+
coordinator_name_can_be_dynamic_terms(_) ->
225+
BinName = <<(atom_to_binary(?FUNCTION_NAME))/binary, (crypto:strong_rand_bytes(8))/binary>>,
226+
SomePlan = [{1000, fun(_Event) -> ok end}],
227+
Names = [{some_composed_tuple},
228+
[list, made_of, atoms],
229+
base64:encode(BinName)],
230+
[ ?assertEqual(ok, amoc_coordinator:start(Name, SomePlan)) || Name <- Names ],
231+
[ {ok, _, _Workers} = amoc_coordinator_sup:get_workers(Name) || Name <- Names ],
232+
[ [amoc_coordinator:add(Name, User) || User <- lists:seq(1, 10)] || Name <- Names ],
233+
[ amoc_coordinator:stop(Name) || Name <- Names ].
234+
223235
failing_action_does_not_kill_the_worker(_) ->
224236
Name = ?FUNCTION_NAME,
225237
Plan = {2, [mock_failing()]},

0 commit comments

Comments
 (0)