Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix #280] Fixes and enhancements on sumo event handling.
- Loading branch information
Showing
13 changed files
with
264 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
-module(sumo_config_SUITE). | ||
|
||
%% CT | ||
-export([ | ||
all/0, | ||
init_per_suite/1, | ||
end_per_suite/1, | ||
init_per_testcase/2 | ||
]). | ||
|
||
%% Test Cases | ||
-export([ | ||
t_sumo_config/1, | ||
t_reload_sumo_config/1 | ||
]). | ||
|
||
-define(EXCLUDED_FUNS, [ | ||
module_info, | ||
all, | ||
init_per_suite, | ||
init_per_testcase | ||
]). | ||
|
||
-type config() :: [{atom(), term()}]. | ||
|
||
%%%============================================================================= | ||
%%% Common Test | ||
%%%============================================================================= | ||
|
||
-spec all() -> [atom()]. | ||
all() -> | ||
Exports = ?MODULE:module_info(exports), | ||
[F || {F, _} <- Exports, not lists:member(F, ?EXCLUDED_FUNS)]. | ||
|
||
-spec init_per_suite(config()) -> config(). | ||
init_per_suite(Config) -> | ||
ok = sumo_test_utils:start_apps(), | ||
Docs = application:get_env(sumo_db, docs, []), | ||
Events = application:get_env(sumo_db, events, []), | ||
[{docs, Docs}, {events, Events} | Config]. | ||
|
||
-spec end_per_suite(config()) -> config(). | ||
end_per_suite(Config) -> | ||
cleanup_config(Config), | ||
_ = application:stop(sumo_db), | ||
Config. | ||
|
||
-spec init_per_testcase(atom(), config()) -> config(). | ||
init_per_testcase(_, Config) -> | ||
setup_config(), | ||
Config. | ||
|
||
%%%============================================================================= | ||
%%% Test Cases | ||
%%%============================================================================= | ||
|
||
-spec t_sumo_config(config()) -> ok. | ||
t_sumo_config(_Config) -> | ||
validate_docs(), | ||
|
||
% expected doc managers | ||
ExpectedManagersDoc1 = [ | ||
ev_manager1, | ||
super_ev_manager | ||
], | ||
ExpectedManagersDoc2 = [ | ||
ev_manager1, | ||
ev_manager2, | ||
super_ev_manager | ||
], | ||
ExpectedManagersDoc3 = [ | ||
super_ev_manager | ||
], | ||
|
||
% check event managers | ||
ExpectedManagersDoc1 = sumo_config:get_event_managers(doc1), | ||
ExpectedManagersDoc2 = sumo_config:get_event_managers(doc2), | ||
ExpectedManagersDoc3 = sumo_config:get_event_managers(doc3), | ||
ExpectedManagersDoc3 = sumo_config:get_event_managers(doc4), | ||
|
||
ok. | ||
|
||
-spec t_reload_sumo_config(config()) -> ok. | ||
t_reload_sumo_config(_Config) -> | ||
validate_docs(), | ||
|
||
% set other manager and reload it | ||
NewDocs = [{docX, storeX, #{module => mod1}} | docs()], | ||
application:set_env(sumo_db, docs, NewDocs), | ||
application:set_env(sumo_db, events, [ | ||
{docX, ev_managerX}, | ||
{'_', super_ev_manager} | ||
]), | ||
sumo_config:init(), | ||
|
||
% expected doc managers | ||
ExpectedManagersDoc1 = [ | ||
ev_managerX, | ||
super_ev_manager | ||
], | ||
ExpectedManagersDoc2 = [ | ||
super_ev_manager | ||
], | ||
|
||
% check event managers | ||
ExpectedManagersDoc2 = sumo_config:get_event_managers(doc1), | ||
ExpectedManagersDoc2 = sumo_config:get_event_managers(doc2), | ||
ExpectedManagersDoc2 = sumo_config:get_event_managers(doc3), | ||
ExpectedManagersDoc2 = sumo_config:get_event_managers(doc4), | ||
ExpectedManagersDoc1 = sumo_config:get_event_managers(docX), | ||
|
||
ok. | ||
|
||
%%%============================================================================= | ||
%%% Internal functions | ||
%%%============================================================================= | ||
|
||
%% @private | ||
setup_config() -> | ||
ok = application:set_env(sumo_db, docs, docs()), | ||
ok = application:set_env(sumo_db, events, events()), | ||
sumo_config:init(). | ||
|
||
%% @private | ||
cleanup_config(Config) -> | ||
Docs = sumo_utils:keyfind(docs, Config), | ||
Events = sumo_utils:keyfind(events, Config), | ||
ok = application:set_env(sumo_db, docs, Docs), | ||
ok = application:set_env(sumo_db, events, Events). | ||
|
||
%% @private | ||
docs() -> | ||
[{doc1, store1, #{module => mod1}}, | ||
{doc2, store2, #{module => mod2}}, | ||
{doc3, store3, #{module => mod3}}, | ||
{doc4, store4, #{module => mod4}}]. | ||
|
||
%% @private | ||
events() -> | ||
[{doc1, ev_manager1}, | ||
{doc2, [ev_manager1, ev_manager2]}, | ||
{doc4, []}, | ||
{'_', super_ev_manager}]. | ||
|
||
%% @private | ||
validate_docs() -> | ||
Docs = lists:usort([DocName || {DocName, _, _} <- docs()]), | ||
Docs = lists:usort([DocName || {DocName, _, _} <- sumo_config:get_docs()]), | ||
ok. |
Oops, something went wrong.