diff --git a/src/ggs_coordinator.erl b/src/ggs_coordinator.erl index 4e6b623..a28fc2a 100644 --- a/src/ggs_coordinator.erl +++ b/src/ggs_coordinator.erl @@ -16,8 +16,8 @@ start_link() -> gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). %% @doc Terminates the coordinator process. -stop(_Reason) -> - ggs_logger:not_implemented(). +stop(Reason) -> + gen_server:cast(ggs_coordinator, {stop, Reason}). %% @doc Joins table with specified token join_table(_Token) -> @@ -52,6 +52,9 @@ init([]) -> handle_call(_Message, _From, State) -> {noreply, State}. +handle_cast({stop, Reason}, State) -> + {stop, normal, state}; + handle_cast(_Message, State) -> {noreply, State}. diff --git a/tests/ggs_coordinator_test.erl b/tests/ggs_coordinator_test.erl new file mode 100644 index 0000000..03b5389 --- /dev/null +++ b/tests/ggs_coordinator_test.erl @@ -0,0 +1,16 @@ +-module(ggs_coordinator_test). +-include_lib("eunit/include/eunit.hrl"). + +start_link_test() -> + {ok, Coord} = ggs_coordinator:start_link(), % Start + PInfo = erlang:process_info(Coord), % Check process info + ggs_coordinator:stop(""), % Clean up + timer:sleep(100), % Wait for cleaning.. + ?assert((PInfo /= undefined)). % Did the server start? + +stop_test() -> + ok = ggs_coordinator:stop(""), % Extra cleaning + {ok, Coord} = ggs_coordinator:start_link(), % Start server + ggs_coordinator:stop("Terminate now"), % Send stop message + timer:sleep(100), % Wait for cleaning.. + ?assert((erlang:process_info(Coord) == undefined)). % Did it stop?