1: %%============================================================================== 2: %% Copyright 2013 Erlang Solutions Ltd. 3: %% 4: %% Licensed under the Apache License, Version 2.0 (the "License"); 5: %% you may not use this file except in compliance with the License. 6: %% You may obtain a copy of the License at 7: %% 8: %% http://www.apache.org/licenses/LICENSE-2.0 9: %% 10: %% Unless required by applicable law or agreed to in writing, software 11: %% distributed under the License is distributed on an "AS IS" BASIS, 12: %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13: %% See the License for the specific language governing permissions and 14: %% limitations under the License. 15: %%============================================================================== 16: 17: -module(metrics_register_SUITE). 18: -compile([export_all, nowarn_export_all]). 19: 20: -include_lib("escalus/include/escalus.hrl"). 21: -include_lib("common_test/include/ct.hrl"). 22: 23: -define(WAIT_TIME, 500). 24: -define(RT_WAIT_TIME, 60000). 25: 26: -import(distributed_helper, [mim/0, 27: require_rpc_nodes/1, 28: rpc/4]). 29: 30: -import(metrics_helper, [assert_counter/2, 31: get_counter_value/1]). 32: 33: -import(domain_helper, [host_type/0]). 34: 35: %%-------------------------------------------------------------------- 36: %% Suite configuration 37: %%-------------------------------------------------------------------- 38: 39: all() -> 40: [{group, registration}]. 41: 42: groups() -> 43: [{registration, [sequence], [register, 44: unregister]}]. 45: 46: suite() -> 47: require_rpc_nodes([mim]) ++ escalus:suite(). 48: 49: %%-------------------------------------------------------------------- 50: %% Init & teardown 51: %%-------------------------------------------------------------------- 52: 53: init_per_suite(Config) -> 54: escalus:init_per_suite(Config). 55: 56: end_per_suite(Config) -> 57: escalus:end_per_suite(Config). 58: 59: init_per_group(_GroupName, Config) -> 60: Config. 61: 62: end_per_group(_GroupName, _Config) -> 63: ok. 64: 65: init_per_testcase(unregister, Config) -> 66: Alice = escalus_users:get_user_by_name(alice), 67: escalus_users:create_user(Config, Alice), 68: Config; 69: init_per_testcase(registered_users, Config) -> 70: case rpc(mim(), mongoose_config, get_opt, [[{auth, host_type()}, methods], []]) of 71: [external] -> 72: {skip, "counter not supported with ejabberd_auth_external"}; 73: [anonymous] -> 74: {skip, "counter not supported with anonymous authentication"}; 75: _ -> 76: Config 77: end; 78: init_per_testcase(_CaseName, Config) -> 79: Config. 80: 81: end_per_testcase(unregister, _Config) -> 82: ok; 83: end_per_testcase(_CaseName, Config) -> 84: Alice = escalus_users:get_user_by_name(alice), 85: escalus_users:delete_user(Config, Alice). 86: 87: %%-------------------------------------------------------------------- 88: %% Registration tests 89: %%-------------------------------------------------------------------- 90: 91: register(Config) -> 92: {value, Registrations} = get_counter_value(modRegisterCount), 93: 94: Alice = escalus_users:get_user_by_name(alice), 95: escalus_users:create_user(Config, Alice), 96: wait_for_registrations(Registrations + 1). 97: 98: unregister(Config) -> 99: {value, Deregistrations} = get_counter_value(modUnregisterCount), 100: 101: Alice = escalus_users:get_user_by_name(alice), 102: escalus_users:delete_user(Config, Alice), 103: wait_for_deregistrations(Deregistrations + 1). 104: 105: %%-------------------------------------------------------------------- 106: %% Helpers 107: %%-------------------------------------------------------------------- 108: 109: wait_for_registrations(Count) -> 110: mongoose_helper:wait_until(fun() -> assert_counter(Count, modRegisterCount) end, 111: {value, Count}, 112: #{name => assert_counter}). 113: 114: wait_for_deregistrations(Count) -> 115: mongoose_helper:wait_until(fun() -> assert_counter(Count, modUnregisterCount) end, 116: {value, Count}, 117: #{name => assert_counter}).