Skip to content

Commit

Permalink
test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kjnilsson committed Apr 24, 2024
1 parent 41d86a8 commit 491e570
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 25 deletions.
19 changes: 0 additions & 19 deletions src/ra_leaderboard.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,3 @@ lookup(ClusterName) ->
error:badarg ->
undefined
end.
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

lookup_leader_test() ->
ClusterName = <<"mah-cluster">>,
?assertEqual(undefined, lookup_leader(ClusterName)),
init(),
?assertEqual(undefined, lookup_leader(ClusterName)),
Me = {me, node()},
record(ClusterName, Me, [Me]),
?assertEqual(Me, lookup_leader(ClusterName)),
?assertEqual([Me], lookup_members(ClusterName)),
You = {you, node()},
record(ClusterName, You, [Me, You]),
?assertEqual(You, lookup_leader(ClusterName)),
?assertEqual([Me, You], lookup_members(ClusterName)),

ok.
-endif.
3 changes: 0 additions & 3 deletions src/ra_systems_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,3 @@ init([]) ->
{Intensity, Period} = application:get_env(ra, ra_systems_sup_intensity, {1, 5}),
SupFlags = #{strategy => one_for_one, intensity => Intensity, period => Period},
{ok, {SupFlags, []}}.



4 changes: 2 additions & 2 deletions test/coordination_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ start_follower(N, PrivDir, SysCfg) ->
ok = ct_rpc:call(S, ?MODULE, node_setup, [Dir0]),
% ok = ct_rpc:call(S, logger, set_primary_config,
% [level, all]),
{ok, _} = ct_cover:add_nodes([S]),
_ = ct_cover:add_nodes([S]),
{ok, _} = ct_rpc:call(S, ?MODULE, ra_start, [[], SysCfg]),
S.

Expand Down Expand Up @@ -1306,6 +1306,6 @@ server_recover_function(System) ->
stop_nodes([{_, _} | _ ] = ServerIds) ->
stop_nodes([S || {_, S} <- ServerIds]);
stop_nodes(Nodes) ->
ok = ct_cover:remove_nodes(Nodes),
_ = ct_cover:remove_nodes(Nodes),
[ok = slave:stop(S) || S <- Nodes],
ok.
58 changes: 58 additions & 0 deletions test/ra_leaderboard_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-module(ra_leaderboard_SUITE).

-compile(nowarn_export_all).
-compile(export_all).

-export([
]).

% -include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

%%%===================================================================
%%% Common Test callbacks
%%%===================================================================

all() ->
[lookup_leader].

mods() ->
[
ra_flru,
ra_lib,
ra_log,
ra_log_reader,
ra_log_segment,
ra_monitors,
ra_server,
ra_snapshot
].

groups() ->
[{tests, all()}].

init_per_group(_, Config) ->
Config.

end_per_group(_Group, _Config) ->
ok.

%%%===================================================================
%%% Test cases
%%%===================================================================

lookup_leader(_Config) ->
ClusterName = <<"mah-cluster">>,
?assertEqual(undefined, ra_leaderboard:lookup_leader(ClusterName)),
ra_leaderboard:init(),
?assertEqual(undefined, ra_leaderboard:lookup_leader(ClusterName)),
Me = {me, node()},
ra_leaderboard:record(ClusterName, Me, [Me]),
?assertEqual(Me, ra_leaderboard:lookup_leader(ClusterName)),
?assertEqual([Me], ra_leaderboard:lookup_members(ClusterName)),
You = {you, node()},
ra_leaderboard:record(ClusterName, You, [Me, You]),
?assertEqual(You, ra_leaderboard:lookup_leader(ClusterName)),
?assertEqual([Me, You],ra_leaderboard:lookup_members(ClusterName)),
ets:delete(ra_leaderboard),
ok.
7 changes: 6 additions & 1 deletion test/ra_snapshot_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ all() ->


all_tests() ->
[
[unit,
init_empty,
init_multi,
take_snapshot,
Expand Down Expand Up @@ -79,6 +79,11 @@ end_per_testcase(_TestCase, _Config) ->
%%% Test cases
%%%===================================================================

unit(_Config) ->
ra_snapshot:random_idxs_to_take_test(),
ra_snapshot:lists_take_idxs_test(),
ok.

init_empty(Config) ->
UId = ?config(uid, Config),
State = init_state(Config),
Expand Down
58 changes: 58 additions & 0 deletions test/unit_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-module(unit_SUITE).

-compile(nowarn_export_all).
-compile(export_all).

-export([
]).

% -include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

%%%===================================================================
%%% Common Test callbacks
%%%===================================================================

all() ->
[unit_tests].

mods() ->
[
ra_flru,
ra_lib,
ra_log,
ra_log_reader,
ra_log_segment,
ra_monitors,
ra_server,
ra_snapshot
].

groups() ->
[{M, [],
[F || {F, 0} <- M:module_info(functions),
re:run(atom_to_list(F), "_test$") =/= nomatch]}
|| M <- mods()].

init_per_group(_, Config) ->
Config.

end_per_group(_Group, _Config) ->
ok.

%%%===================================================================
%%% Test cases
%%%===================================================================

all_tests() ->
[{M, [F || {F, 0} <- M:module_info(functions),
re:run(atom_to_list(F), "_test$") =/= nomatch]}
|| M <- mods()].

unit_tests(_Config) ->
[begin
ct:pal("Running ~s ~b tests", [M, length(Tests)]),
[M:F() || F <- Tests],
ok
end || {M, Tests} <- all_tests()],
ok.

0 comments on commit 491e570

Please sign in to comment.