From b4ee4909d42a16548adcae2b3e8798c1a1192350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Fri, 19 Apr 2024 10:23:07 +0200 Subject: [PATCH] Test mod_muc instrumentation events --- big_tests/tests/muc_SUITE.erl | 57 +++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/big_tests/tests/muc_SUITE.erl b/big_tests/tests/muc_SUITE.erl index 2e2fd7e8d08..d14d85a837a 100644 --- a/big_tests/tests/muc_SUITE.erl +++ b/big_tests/tests/muc_SUITE.erl @@ -45,7 +45,9 @@ disco_service_story/1, story_with_room/4, change_nick_form_iq/1, - set_nick/2 + set_nick/2, + assert_room_event/2, + wait_for_probe_event/2 ]). -import(domain_helper, [host_type/0, domain/0]). @@ -262,7 +264,8 @@ groups() -> ]}, {owner_no_parallel, [], [ room_creation_not_allowed, - create_instant_persistent_room + create_instant_persistent_room, + probe_metrics_are_updated ]}, {room_management, [], [ create_and_destroy_room, @@ -327,19 +330,23 @@ suite() -> init_per_suite(Config) -> %% For mocking with unnamed functions mongoose_helper:inject_module(?MODULE), + instrument_helper:start(instrument_helper:declared_events(mod_muc)), Config2 = escalus:init_per_suite(Config), Config3 = dynamic_modules:save_modules(host_type(), Config2), + Config4 = backup_and_set_config_option(Config3, [instrumentation, probe_interval], 1), dynamic_modules:restart(host_type(), mod_disco, default_mod_config(mod_disco)), muc_helper:load_muc(), mongoose_helper:ensure_muc_clean(), - Config3. + Config4. end_per_suite(Config) -> escalus_fresh:clean(), mongoose_helper:ensure_muc_clean(), muc_helper:unload_muc(), dynamic_modules:restore_modules(Config), - escalus:end_per_suite(Config). + restore_config_option(Config, [instrumentation, probe_interval]), + escalus:end_per_suite(Config), + instrument_helper:stop(). init_per_group(room_registration_race_condition, Config) -> escalus_fresh:create_users(Config, [{alice, 1}]); @@ -3078,6 +3085,27 @@ disco_items_nonpublic(ConfigIn) -> escalus:assert(is_error, [<<"auth">>, <<"forbidden">>], Error) end). +probe_metrics_are_updated(Config) -> + OnlineCount = rpc(mim(), mod_muc, online_rooms_number, [host_type()]), + HibernatedCount = rpc(mim(), mod_muc, hibernated_rooms_number, [host_type()]), + + %% Wait until reported counts are in sync with initial values + wait_for_probe_event(mod_muc_online_rooms, OnlineCount), + wait_for_probe_event(mod_muc_hibernated_rooms, HibernatedCount), + RoomName = fresh_room_name(), + + %% Reported counts should be increased after room creation + Story = fun(Alice) -> + given_fresh_room_is_hibernated(Alice, RoomName, [{membersonly, false}]), + wait_for_probe_event(mod_muc_online_rooms, OnlineCount + 1), + wait_for_probe_event(mod_muc_hibernated_rooms, HibernatedCount + 1) + end, + escalus:fresh_story(Config, [{alice, 1}], Story), + + %% Reported counts should be back to initial values + wait_for_probe_event(mod_muc_online_rooms, OnlineCount), + wait_for_probe_event(mod_muc_hibernated_rooms, HibernatedCount), + destroy_room(muc_host(), RoomName). create_and_destroy_room(Config) -> escalus:story(Config, [{alice, 1}], fun(Alice) -> @@ -4307,14 +4335,14 @@ room_with_participants_is_hibernated(Config) -> hibernation_metrics_are_updated(Config) -> RoomName = fresh_room_name(), escalus:fresh_story(Config, [{alice, 1}], fun(Alice) -> - given_fresh_room_is_hibernated(Alice, RoomName, [{membersonly, false}]), + Result = given_fresh_room_is_hibernated(Alice, RoomName, [{membersonly, false}]), + {ok, RoomJid, _Pid} = Result, OnlineRooms = rpc(mim(), mod_muc, online_rooms_number, []), - true = OnlineRooms > 0, - HibernationsCnt = get_spiral_metric_count(global, [mod_muc, hibernations]), - true = HibernationsCnt > 0, + ?assert(OnlineRooms > 0), + assert_room_event(mod_muc_hibernations, RoomJid), HibernatedRooms = rpc(mim(), mod_muc, hibernated_rooms_number, []), - true = HibernatedRooms > 0 + ?assert(HibernatedRooms > 0) end), destroy_room(muc_host(), RoomName). @@ -4467,20 +4495,17 @@ can_found_in_db_when_stopped(Config) -> deep_hibernation_metrics_are_updated(Config) -> RoomName = fresh_room_name(), escalus:fresh_story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> - {ok, _, Pid} = given_fresh_room_is_hibernated( - Alice, RoomName, [{persistentroom, true}]), + {ok, RoomJid, Pid} = given_fresh_room_is_hibernated( + Alice, RoomName, [{persistentroom, true}]), true = wait_for_room_to_be_stopped(Pid, timer:seconds(8)), - DeepHibernations = get_spiral_metric_count(global, [mod_muc, deep_hibernations]), - true = DeepHibernations > 0, + assert_room_event(mod_muc_deep_hibernations, RoomJid), Unavailable = escalus:wait_for_stanza(Alice), escalus:assert(is_presence_with_type, [<<"unavailable">>], Unavailable), escalus:send(Bob, stanza_join_room(RoomName, <<"bob">>)), escalus:wait_for_stanzas(Bob, 2), - - Recreations = get_spiral_metric_count(global, [mod_muc, process_recreations]), - true = Recreations > 0 + assert_room_event(mod_muc_process_recreations, RoomJid) end),