diff options
| author | Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> | 2020-03-19 12:41:50 +0100 |
|---|---|---|
| committer | Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> | 2020-03-19 15:26:44 +0100 |
| commit | e9547d3eaf6f8fddbc1f8bebfe93eb0b3d804d3b (patch) | |
| tree | 895cb69003bdc61e857d304f1a9818fd96ad1346 /src | |
| parent | abc0b522de83e36650e873d2065646dc1f4ae1d4 (diff) | |
| download | rabbitmq-server-git-e9547d3eaf6f8fddbc1f8bebfe93eb0b3d804d3b.tar.gz | |
rabbit_feature_flags: Add an API for testsuites to add their own feature flags
This should be more robust than relying the caller (through a forced
exception). Way more robust considering that the latter seems to not
work at all :)
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_feature_flags.erl | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/src/rabbit_feature_flags.erl b/src/rabbit_feature_flags.erl index b8554cc9d6..db13b7347e 100644 --- a/src/rabbit_feature_flags.erl +++ b/src/rabbit_feature_flags.erl @@ -129,7 +129,8 @@ do_sync_feature_flags_with_node/1]). -ifdef(TEST). --export([initialize_registry/3, +-export([inject_test_feature_flags/1, + initialize_registry/3, query_supported_feature_flags/0, mark_as_enabled_remotely/2, mark_as_enabled_remotely/4]). @@ -967,37 +968,22 @@ do_initialize_registry(AllFeatureFlags, %% @private -ifdef(TEST). +-define(PT_TESTSUITE_ATTRS, {?MODULE, testsuite_feature_flags_attrs}). + +inject_test_feature_flags(AttributesFromTestsuite) -> + rabbit_log_feature_flags:debug( + "Feature flags: injecting feature flags from testsuite: ~p", + [AttributesFromTestsuite]), + ok = persistent_term:put(?PT_TESTSUITE_ATTRS, AttributesFromTestsuite), + initialize_registry(). + module_attributes_from_testsuite() -> - try - throw(force_exception) - catch - throw:force_exception:Stacktrace -> - Modules = lists:filter( - fun({Mod, _, _, _}) -> - ModS = atom_to_list(Mod), - re:run(ModS, "_SUITE$", [{capture, none}]) - =:= - match - end, Stacktrace), - case Modules of - [{Module, _, _, _} | _] -> - ModInfo = Module:module_info(attributes), - Attrs = lists:append( - [Attr || {Name, Attr} <- ModInfo, - Name =:= rabbit_feature_flag]), - case Attrs of - [] -> []; - _ -> [{Module, Module, Attrs}] - end; - _ -> - [] - end - end. + persistent_term:get(?PT_TESTSUITE_ATTRS, []). query_supported_feature_flags() -> rabbit_log_feature_flags:debug( - "Feature flags: query feature flags in loaded applications + test " - "module"), + "Feature flags: query feature flags in loaded applications " + "+ testsuite"), T0 = erlang:timestamp(), AttributesPerApp = rabbit_misc:rabbitmq_related_module_attributes( rabbit_feature_flag), |
