Skip to content

Commit

Permalink
Return a more explicit running status from the controller
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Dec 19, 2023
1 parent 9459926 commit 8590a36
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion integration_test/extra_code_paths/path1/dummy_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_amoc_dist() ->
Slaves = amoc_cluster:slave_nodes(),
%% check the status of the nodes
disabled = rpc:call(Master, amoc_controller, get_status, []),
[{running, dummy_scenario, _, _} = rpc:call(Node, amoc_controller, get_status, [])
[{running, #{scenario := dummy_scenario}} = rpc:call(Node, amoc_controller, get_status, [])
|| Node <- Slaves],
%% check user ids
{N1, Nodes1, Ids1, Max1} = get_users_info(Slaves),
Expand Down
2 changes: 1 addition & 1 deletion src/amoc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ do(Scenario, Count, Settings) ->
add(Count) when is_integer(Count), Count > 0 ->
case is_running_locally() of
ok ->
{running, _, _, LastUserId} = amoc_controller:get_status(),
{running, #{highest_user_id := LastUserId}} = amoc_controller:get_status(),
amoc_controller:add_users(LastUserId + 1, LastUserId + Count);
Error -> Error
end.
Expand Down
8 changes: 6 additions & 2 deletions src/amoc_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
-type state() :: #state{}.
%% Internal state of the node's controller
-type handle_call_res() :: ok | {ok, term()} | {error, term()}.
-type running_status() :: #{scenario := amoc:scenario(),
currently_running_users := user_count(),
highest_user_id := last_user_id()}.
%% Details about the scenario currently running
-type amoc_status() :: idle |
{running, amoc:scenario(), user_count(), last_user_id()} |
{running, running_status()} |
{terminating, amoc:scenario()} |
{finished, amoc:scenario()} |
{error, any()} |
Expand Down Expand Up @@ -259,7 +263,7 @@ handle_remove(_Count, _ForceRemove, #state{status = Status}) ->
-spec handle_status(state()) -> amoc_status().
handle_status(#state{status = running, scenario = Scenario,
no_of_users = N, last_user_id = LastId}) ->
{running, Scenario, N, LastId};
{running, #{scenario => Scenario, currently_running_users => N, highest_user_id => LastId}};
handle_status(#state{status = terminating, scenario = Scenario}) ->
{terminating, Scenario};
handle_status(#state{status = finished, scenario = Scenario}) ->
Expand Down
10 changes: 8 additions & 2 deletions test/controller_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ start_scenario_runs_fine(_) ->
start_scenario_check_status(_) ->
do_start_scenario(testing_scenario, regular_vars()),
Status = amoc_controller:get_status(),
?assertMatch({running, testing_scenario, 0, 0}, Status).
?assertMatch(
{running, #{scenario := testing_scenario,
currently_running_users := 0,
highest_user_id := 0}},
Status).

add_users_to_started_scenario(_) ->
do_start_scenario(testing_scenario, regular_vars()),
Expand Down Expand Up @@ -178,5 +182,7 @@ other_vars_to_keep_quiet() ->

wait_until_scenario_has_users(Scenario, Current, HighestId) ->
WaitUntilFun = fun amoc_controller:get_status/0,
WaitUntilValue = {running, Scenario, Current, HighestId},
WaitUntilValue = {running, #{scenario => Scenario,
currently_running_users => Current,
highest_user_id => HighestId}},
async_helper:wait_until(WaitUntilFun, WaitUntilValue).

0 comments on commit 8590a36

Please sign in to comment.