diff --git a/big_tests/tests/service_domain_db_SUITE.erl b/big_tests/tests/service_domain_db_SUITE.erl index 7ec46708c76..df0f99ac306 100644 --- a/big_tests/tests/service_domain_db_SUITE.erl +++ b/big_tests/tests/service_domain_db_SUITE.erl @@ -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]). @@ -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) -> @@ -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, @@ -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]). @@ -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]]), @@ -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. diff --git a/src/domain/service_domain_db.erl b/src/domain/service_domain_db.erl index 0c6970748c6..ebb94946241 100644 --- a/src/domain/service_domain_db.erl +++ b/src/domain/service_domain_db.erl @@ -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]). @@ -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() -> @@ -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), @@ -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).