Skip to content

Commit

Permalink
re-enabling rebar_lint
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysGonchar committed Aug 3, 2023
1 parent 834b5f9 commit dac0978
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 24 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: default rel compile clean ct test integration_test dialyzer xref console
.PHONY: default rel compile clean ct test integration_test dialyzer xref console lint

REBAR = rebar3

Expand All @@ -25,7 +25,10 @@ ct:
## eunit and ct commands always add a test profile to the run
$(REBAR) ct --verbose $(SUITE_OPTS)

test: compile xref dialyzer ct
lint:
$(REBAR) as elvis lint

test: compile xref dialyzer ct lint

integration_test:
./integration_test/stop_demo_cluster.sh
Expand Down
28 changes: 28 additions & 0 deletions elvis.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[{elvis, [
{config, [
#{dirs => ["src", "src/*", "scenarios"],
filter => "*.erl",
ruleset => erl_files,
rules => [
{elvis_style, invalid_dynamic_call, #{ignore => [amoc_user]}},
{elvis_style, export_used_types, disable},
{elvis_style, no_throw, #{ignore => [{amoc_config, get, 2}] }},
{elvis_text_style, line_length, #{skip_comments => whole_line }},
{elvis_style, no_block_expressions, disable}
]},
#{dirs => ["test"],
filter => "*.erl",
ruleset => erl_files,
rules => [
{elvis_style, function_naming_convention, #{regex => "^[a-z]([a-z0-9]*_?)*$"}},
{elvis_style, atom_naming_convention, #{regex => "^[a-z]([a-z0-9]*_?)*(_SUITE)?$"}},
{elvis_style, dont_repeat_yourself, #{min_complexity => 50}},
{elvis_style, no_debug_call, disable},
{elvis_style, no_throw, disable},
{elvis_style, no_import, disable}
]},
#{dirs => ["."],
filter => "rebar.config",
ruleset => rebar_config}
]}
]}].
1 change: 1 addition & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{fusco, "0.1.1"}
]}
]},
{elvis, [{plugins, [{rebar3_lint, "3.0.1"}]}]},
{demo, [
{erl_opts, [debug_info, {src_dirs, ["src", "scenarios"]}]},
{relx, [
Expand Down
4 changes: 2 additions & 2 deletions src/amoc_config/amoc_config_attributes.erl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ make_module_parameter(#{name := Name, description := Description, default_value
maybe_verification_fun() | not_exported | invalid_method.
verification_fn(none) ->
fun ?MODULE:none/1;
verification_fn([_ | _] = OneOF) ->
one_of_fun(OneOF);
verification_fn([_ | _] = OneOf) ->
one_of_fun(OneOf);
verification_fn(Fun) when is_function(Fun, 1) ->
is_exported(Fun);
verification_fn({Module, Function, 1}) ->
Expand Down
4 changes: 2 additions & 2 deletions src/amoc_config/amoc_config_env.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ parse_value(String, _) ->
try Mod:parse_value(String) of
{ok, Value} -> {ok, Value};
{error, Error} -> {error, Error};
InvalidRetValue -> {error,{parser_returned_invalid_value, InvalidRetValue}}
InvalidRetValue -> {error, {parser_returned_invalid_value, InvalidRetValue}}
catch
Class:Error:Stacktrace ->
{error,{parser_crashed, {Class, Error, Stacktrace}}}
{error, {parser_crashed, {Class, Error, Stacktrace}}}
end.
14 changes: 7 additions & 7 deletions src/amoc_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ update_settings(Settings) ->

-spec add_users(amoc_scenario:user_id(), amoc_scenario:user_id()) ->
ok | {error, term()}.
add_users(StartId, EndID) ->
telemetry:execute([amoc, controller, users], #{count => EndID - StartId + 1}, #{type => add}),
add_users(StartId, EndId) ->
telemetry:execute([amoc, controller, users], #{count => EndId - StartId + 1}, #{type => add}),
%% adding the exact range of the users
gen_server:call(?SERVER, {add, StartId, EndID}).
gen_server:call(?SERVER, {add, StartId, EndId}).

-spec remove_users(user_count(), boolean()) -> {ok, user_count()}.
remove_users(Count, ForceRemove) ->
Expand Down Expand Up @@ -145,8 +145,8 @@ handle_call(stop_scenario, _From, State) ->
handle_call({update_settings, Settings}, _From, State) ->
RetValue = handle_update_settings(Settings, State),
{reply, RetValue, State};
handle_call({add, StartId, EndID}, _From, State) ->
{RetValue, NewState} = handle_add(StartId, EndID, State),
handle_call({add, StartId, EndId}, _From, State) ->
{RetValue, NewState} = handle_add(StartId, EndId, State),
{reply, RetValue, NewState};
handle_call({remove, Count, ForceRemove}, _From, State) ->
RetValue = handle_remove(Count, ForceRemove, State),
Expand Down Expand Up @@ -296,13 +296,13 @@ init_scenario(Scenario, Settings) ->
{error, Type, Reason} -> {error, {Type, Reason}}
end.

-spec maybe_start_timer(timer:tref()|undefined) -> timer:tref().
-spec maybe_start_timer(timer:tref() | undefined) -> timer:tref().
maybe_start_timer(undefined) ->
{ok, TRef} = timer:send_interval(interarrival(), start_user),
TRef;
maybe_start_timer(TRef) -> TRef.

-spec maybe_stop_timer(timer:tref()|undefined) -> undefined.
-spec maybe_stop_timer(timer:tref() | undefined) -> undefined.
maybe_stop_timer(undefined) ->
undefined;
maybe_stop_timer(TRef) ->
Expand Down
3 changes: 2 additions & 1 deletion src/amoc_coordinator/amoc_coordinator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ start(Name, CoordinationPlan, Timeout) when ?IS_TIMEOUT(Timeout) ->
%% end, we need to add them first.
AllItemsHandlers = lists:reverse([Item || {all, _} = Item <- Plan]),
[gen_event:add_handler(Name, ?MODULE, {Name, Item}) || Item <- AllItemsHandlers],
[gen_event:add_handler(Name, ?MODULE, {Name, Item}) || {N, _} = Item <- Plan, is_integer(N)],
[gen_event:add_handler(Name, ?MODULE, {Name, Item}) || {N, _} = Item <- Plan,
is_integer(N)],
gen_event:add_handler(Name, ?MODULE, {timeout, Name, Timeout}),
ok;
{error, _} -> error
Expand Down
4 changes: 3 additions & 1 deletion src/amoc_distribution/amoc_cluster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ connect_nodes(Node, Nodes) ->
set_master_node(Node, Action) ->
case gen_server:call({?SERVER, Node}, {set_master_node, node()}) of
ok ->
case catch apply(Action, [Node]) of
try apply(Action, [Node]) of
ok -> gen_server:cast(?SERVER, {add_slave, Node});
RetValue -> {error, {invalid_action_ret_value, RetValue}}
catch
C:E:S -> {error, {invalid_action_ret_value, {C, E, S}}}
end;
Error -> Error
end.
Expand Down
2 changes: 1 addition & 1 deletion src/amoc_distribution/amoc_dist.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

-compile({no_auto_import, [ceil/1]}).

-type cluster_state():: idle | running | stopped.
-type cluster_state() :: idle | running | stopped.
%% ------------------------------------------------------------------
%% API
%% ------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/amoc_throttle/amoc_throttle.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ change_rate_gradually(Name, LowRate, HighRate, RateInterval, StepInterval, NoOfS
%% destroy Async runner
%% '''
%% for the local execution, req/exec rates are increased only by throttle process.
-spec run(name(), fun(()-> any())) -> ok | {error, any()}.
-spec run(name(), fun(() -> any())) -> ok | {error, any()}.
run(Name, Fn) ->
amoc_throttle_controller:run(Name, Fn).

Expand Down
9 changes: 6 additions & 3 deletions src/amoc_throttle/amoc_throttle_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ start_link() ->
ensure_throttle_processes_started(Name, Interval, Rate, NoOfProcesses) ->
gen_server:call(?MASTER_SERVER, {start_processes, Name, Interval, Rate, NoOfProcesses}).

-spec run(name(), fun(()-> any())) -> ok | {error, any()}.
-spec run(name(), fun(() -> any())) -> ok | {error, any()}.
run(Name, Fn) ->
case get_throttle_process(Name) of
{ok, Pid} ->
Expand Down Expand Up @@ -239,7 +239,7 @@ rate_per_minute(Rate, Interval) ->
start_processes(Name, Rate, Interval, NoOfProcesses) ->
% Master metrics
RatePerMinute = rate_per_minute(Rate, Interval),
telemetry:execute([amoc, throttle, rate], #{rate => RatePerMinute}, #{name => Name}),
report_rate(Name, RatePerMinute),
RealNoOfProcesses = min(Rate, NoOfProcesses),
start_throttle_processes(Name, Interval, Rate, RealNoOfProcesses),
RealNoOfProcesses.
Expand Down Expand Up @@ -273,7 +273,7 @@ do_change_rate(Name, Rate, Interval) ->
[] -> {error, no_processes_in_group};
List when is_list(List) ->
RatePerMinute = rate_per_minute(Rate, Interval),
telemetry:execute([amoc, throttle, rate], #{rate => RatePerMinute}, #{name => Name}),
report_rate(Name, RatePerMinute),
update_throttle_processes(List, Interval, Rate, length(List)),
{ok, RatePerMinute}
end.
Expand Down Expand Up @@ -317,3 +317,6 @@ run_cmd(Pid, pause) ->
amoc_throttle_process:pause(Pid);
run_cmd(Pid, resume) ->
amoc_throttle_process:resume(Pid).

report_rate(Name, RatePerMinute) ->
telemetry:execute([amoc, throttle, rate], #{rate => RatePerMinute}, #{name => Name}).
5 changes: 3 additions & 2 deletions test/amoc_config_env_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ init_per_suite(Config) ->
ct:pal("OS env:~n ~p", [os:getenv()]),
Config.

end_per_suite(_)->
end_per_suite(_) ->
%% unset predefined variables
unset_os_env(set_var),
unset_os_env(empty_var).
Expand All @@ -38,7 +38,8 @@ init_per_testcase(valid_custom_parser_test, Config) ->
App = application:get_application(amoc_config_env),
application:set_env(App, config_parser_mod, ?MOCK_MOD),
ct:pal("amoc_config_env module belongs to '~p' application", [App]),
ct:pal("AMOC_* OS env. variables:~n ~p", [[AmocEnv || "AMOC_" ++ _ = AmocEnv <- os:getenv()]]),
ct:pal("AMOC_* OS env. variables:~n ~p",
[[AmocEnv || "AMOC_" ++ _ = AmocEnv <- os:getenv()]]),
Config;
init_per_testcase(invalid_custom_parser_test, Config) ->
App = application:get_application(amoc_config_env),
Expand Down
4 changes: 2 additions & 2 deletions test/amoc_config_verification_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ process_scenario_config_shadows_default_values(_) ->
?assertEqual({ok, ScenarioConfig}, Result4).

process_scenario_config_returns_error_for_invalid_values(_) ->
VerificationFN = fun(_) -> {false, some_reason} end,
VerificationFn = fun(_) -> {false, some_reason} end,
IncorrectScenarioConfig =
[#module_parameter{name = wrong_param, mod = ?MOD, value = any_value,
verification_fn = VerificationFN}
verification_fn = VerificationFn}
| incorrect_scenario_config()],
given_scenario_parameters_not_set(IncorrectScenarioConfig),
Result = amoc_config_verification:process_scenario_config(IncorrectScenarioConfig, []),
Expand Down

0 comments on commit dac0978

Please sign in to comment.