Skip to content

Commit

Permalink
fixing and renaming db_initial_load_crashes_node testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysGonchar committed Mar 26, 2021
1 parent fe627f8 commit 9743f99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
14 changes: 7 additions & 7 deletions big_tests/tests/service_domain_db_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ db_cases() -> [
db_inserted_from_one_node_while_service_disabled_on_another,
db_reinserted_from_one_node_while_service_disabled_on_another,
db_out_of_sync_restarts_service,
db_initial_load_crashes_node
db_crash_on_initial_load_restarts_service
].

-define(APPS, [inets, crypto, ssl, ranch, cowlib, cowboy]).
Expand Down Expand Up @@ -99,8 +99,8 @@ init_per_group(_GroupName, Config) ->
end_per_group(_GroupName, Config) ->
Config.

init_per_testcase(db_initial_load_crashes_node, Config) ->
maybe_setup_meck(db_initial_load_crashes_node),
init_per_testcase(db_crash_on_initial_load_restarts_service, Config) ->
maybe_setup_meck(db_crash_on_initial_load_restarts_service),
init_with(mim(), [], []),
Config;
init_per_testcase(TestcaseName, Config) ->
Expand Down Expand Up @@ -374,7 +374,7 @@ db_reinserted_from_one_node_while_service_disabled_on_another(_) ->
{error, not_found} = get_host_type(mim(), <<"example.com">>),
{error, not_found} = get_host_type(mim2(), <<"example.com">>).

db_initial_load_crashes_node(_) ->
db_crash_on_initial_load_restarts_service(_) ->
service_enabled(mim()),
%% service is restarted
true = rpc(mim(), meck, num_calls, [service_domain_db, restart, 0]) > 0,
Expand Down Expand Up @@ -423,7 +423,7 @@ init_with(Node, Pairs, AllowedHostTypes) ->
rpc(Node, mongoose_domain_core, stop, []),
rpc(Node, mongoose_domain_core, start, [Pairs, AllowedHostTypes]),
%% call restart to reset last event id
rpc(Node, service_domain_db, restart, []).
rpc(Node, service_domain_db, reset_last_event_id, []).

insert_domain(Node, Domain, HostType) ->
rpc(Node, mongoose_domain_api, insert_domain, [Domain, HostType]).
Expand Down Expand Up @@ -493,7 +493,7 @@ restore_conf(Node, #{loaded := Loaded, service_opts := ServiceOpts, core_opts :=
ensure_nodes_know_each_other() ->
pong = rpc(mim2(), net_adm, ping, [maps:get(node, mim())]).

maybe_setup_meck(db_initial_load_crashes_node) ->
maybe_setup_meck(db_crash_on_initial_load_restarts_service) ->
ok = rpc(mim(), meck, new, [mongoose_domain_sql, [passthrough, no_link]]),
ok = rpc(mim(), meck, expect, [mongoose_domain_sql, select_from, 2, something_strange]),
ok = rpc(mim(), meck, new, [service_domain_db, [passthrough, no_link]]),
Expand All @@ -504,7 +504,7 @@ maybe_setup_meck(db_out_of_sync_restarts_service) ->
maybe_setup_meck(_TestCase) ->
ok.

maybe_teardown_meck(TC) when TC =:= db_initial_load_crashes_node;
maybe_teardown_meck(TC) when TC =:= db_crash_on_initial_load_restarts_service;
TC =:= db_out_of_sync_restarts_service ->
rpc(mim(), meck, unload, []);
maybe_teardown_meck(_TestCase) -> ok.
20 changes: 13 additions & 7 deletions src/domain/service_domain_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
-export([force_check_for_updates/0]).
-export([sync/0, sync_local/0]).

%% exported for integration tests only!
-export([reset_last_event_id/0]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
Expand All @@ -38,14 +41,11 @@ stop() ->
ok.

restart() ->
%% if service goes out of sync. with DB this interface
%% can be used to restart the service. to ensure that
%% domains table is re-read from scratch we must also
%% reset the last event id.
%% if service goes out of sync with DB this interface
%% can be used to restart the service.
%% it's enough to just shut down gen_server, supervisor
%% will restart it.
set_last_event_id(undefined),
gen_server:cast(?MODULE, shutdown).
gen_server:cast(?MODULE, reset_and_shutdown).

-spec config_spec() -> mongoose_config_spec:config_section().
config_spec() ->
Expand Down Expand Up @@ -105,7 +105,10 @@ handle_cast(initial_loading, State) ->
NewState = State#{last_event_id => LastEventId,
check_for_updates_interval => 30000},
{noreply, handle_check_for_updates(NewState)};
handle_cast(shutdown, State) ->
handle_cast(reset_and_shutdown, State) ->
%% to ensure that domains table is re-read from
%% scratch, we must reset the last event id.
reset_last_event_id(),
{stop, shutdown, State};
handle_cast(Msg, State) ->
?UNEXPECTED_CAST(Msg),
Expand Down Expand Up @@ -164,3 +167,6 @@ set_last_event_id(LastEventId) ->

get_last_event_id() ->
persistent_term:get(?LAST_EVENT_ID_KEY, undefined).

reset_last_event_id() ->
set_last_event_id(undefined).

0 comments on commit 9743f99

Please sign in to comment.