Skip to content

Commit

Permalink
Move start_link_local test
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed May 9, 2024
1 parent 19fba2f commit c19a3c4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
13 changes: 1 addition & 12 deletions test/cets_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ cases() ->
delete_works,
delete_many_works,
inserted_records_could_be_read_back_from_replicated_table,
bag_with_conflict_handler_not_allowed_for_start_link,
insert_new_works,
insert_new_works_with_table_name,
insert_new_works_when_leader_is_back,
Expand Down Expand Up @@ -237,7 +236,7 @@ log_modules() ->

start_link_inits_and_accepts_records(Config) ->
Tab = make_name(Config),
start_link_local(Tab),
cets_test_setup:start_link_local(Tab),
cets:insert(Tab, {alice, 32}),
[{alice, 32}] = ets:lookup(Tab, alice).

Expand Down Expand Up @@ -1447,16 +1446,6 @@ still_works(Pid) ->
ok = cets:insert(Pid, {1}),
{ok, [{1}]} = cets:remote_dump(Pid).

start_link_local(Name) ->
start_link_local(Name, #{}).

start_link_local(Name, Opts) ->
catch cets:stop(Name),
wait_for_name_to_be_free(node(), Name),
{ok, Pid} = cets:start_link(Name, Opts),
schedule_cleanup(Pid),
{ok, Pid}.

stopped_pid() ->
%% Get a pid for a stopped process
{Pid, Mon} = spawn_monitor(fun() -> ok end),
Expand Down
15 changes: 11 additions & 4 deletions test/cets_join_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ groups() ->
cases() ->
[
join_works,
join_works_with_existing_data,
join_works_with_existing_data_with_conflicts,
join_works_with_existing_data_with_conflicts_and_defined_conflict_handler,
join_works_with_existing_data_with_conflicts_and_defined_conflict_handler_and_more_keys,
join_works_with_existing_data_with_conflicts_and_defined_conflict_handler_and_keypos2,
bag_with_conflict_handler_not_allowed,
bag_with_conflict_handler_not_allowed_for_start_link,
join_with_the_same_pid,
join_ref_is_same_after_join,
join_fails_because_server_process_not_found,
Expand Down Expand Up @@ -194,6 +197,14 @@ join_works_with_existing_data_with_conflicts(Config) ->
[{alice, 33}] = ets:lookup(Tab1, alice),
[{alice, 32}] = ets:lookup(Tab2, alice).

bag_with_conflict_handler_not_allowed(Config) ->
{error, [bag_with_conflict_handler]} =
cets:start(make_name(Config), #{handle_conflict => fun resolve_highest/2, type => bag}).

bag_with_conflict_handler_not_allowed_for_start_link(Config) ->
{error, [bag_with_conflict_handler]} =
cets:start_link(make_name(Config), #{handle_conflict => fun resolve_highest/2, type => bag}).

join_works_with_existing_data_with_conflicts_and_defined_conflict_handler(Config) ->
Opts = #{handle_conflict => fun resolve_highest/2},
Tab1 = make_name(Config, 1),
Expand Down Expand Up @@ -251,10 +262,6 @@ resolve_user_conflict(_U1, U2) ->
resolve_highest({K, A}, {K, B}) ->
{K, max(A, B)}.

bag_with_conflict_handler_not_allowed(Config) ->
{error, [bag_with_conflict_handler]} =
cets:start(make_name(Config), #{handle_conflict => fun resolve_highest/2, type => bag}).

join_with_the_same_pid(Config) ->
Tab = make_name(Config),
{ok, Pid} = start_local(Tab),
Expand Down
12 changes: 12 additions & 0 deletions test/cets_test_setup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
-export([
start_local/1,
start_local/2,
start_link_local/1,
start_link_local/2,
start/2,
start_disco/2,
start_simple_disco/0
Expand Down Expand Up @@ -80,6 +82,16 @@ start(Node, Tab) ->
schedule_cleanup(Pid),
{ok, Pid}.

start_link_local(Name) ->
start_link_local(Name, #{}).

start_link_local(Name, Opts) ->
catch cets:stop(Name),
cets_test_wait:wait_for_name_to_be_free(node(), Name),
{ok, Pid} = cets:start_link(Name, Opts),
schedule_cleanup(Pid),
{ok, Pid}.

start_disco(Node, Opts) ->
case Opts of
#{name := Name} ->
Expand Down

0 comments on commit c19a3c4

Please sign in to comment.