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_c2s_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, 100). 24: 25: -import(metrics_helper, [get_counter_value/1, 26: wait_for_counter/2]). 27: 28: %%-------------------------------------------------------------------- 29: %% Suite configuration 30: %%-------------------------------------------------------------------- 31: 32: all() -> 33: [{group, single}, 34: {group, multiple}, 35: {group, drop}, 36: {group, errors}, 37: {group, count}]. 38: 39: groups() -> 40: [{single, [sequence], [message_one, 41: stanza_one, 42: presence_one, 43: presence_direct_one, 44: iq_one]}, 45: {multiple, [sequence], [messages]}, 46: {drop, [sequence], [bounced 47: ]}, 48: {errors, [sequence], [error_total, 49: error_mesg, 50: error_iq, 51: error_presence]}, 52: {count, [sequence], [stanza_count]}]. 53: 54: suite() -> 55: [{require, ejabberd_node} | escalus:suite()]. 56: 57: %%-------------------------------------------------------------------- 58: %% Init & teardown 59: %%-------------------------------------------------------------------- 60: 61: init_per_suite(Config) -> 62: HostType = domain_helper:host_type(), 63: Config1 = dynamic_modules:save_modules(HostType, Config), 64: dynamic_modules:ensure_stopped(HostType, [mod_offline]), 65: escalus:init_per_suite(Config1). 66: 67: end_per_suite(Config) -> 68: dynamic_modules:restore_modules(Config), 69: escalus:end_per_suite(Config). 70: 71: init_per_group(_GroupName, Config) -> 72: escalus:create_users(Config, escalus:get_users([alice, bob])). 73: 74: end_per_group(_GroupName, Config) -> 75: escalus:delete_users(Config, escalus:get_users([alice, bob])). 76: 77: init_per_testcase(CaseName, Config) -> 78: escalus:init_per_testcase(CaseName, Config). 79: 80: end_per_testcase(CaseName, Config) -> 81: escalus:end_per_testcase(CaseName, Config). 82: 83: %%-------------------------------------------------------------------- 84: %% Message tests 85: %%-------------------------------------------------------------------- 86: 87: 88: message_one(Config) -> 89: {value, MesgSent} = get_counter_value(xmppMessageSent), 90: {value, MesgReceived} = get_counter_value(xmppMessageReceived), 91: escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> 92: 93: escalus_client:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi!">>)), 94: escalus_client:wait_for_stanza(Bob), 95: 96: wait_for_counter(MesgSent + 1, xmppMessageSent), 97: wait_for_counter(MesgReceived + 1, xmppMessageReceived) 98: 99: end). 100: 101: stanza_one(Config) -> 102: escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> 103: {value, StanzaSent} = get_counter_value(xmppStanzaSent), 104: {value, StanzaReceived} = get_counter_value(xmppStanzaReceived), 105: 106: escalus_client:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi!">>)), 107: escalus_client:wait_for_stanza(Bob), 108: 109: wait_for_counter(StanzaSent + 1, xmppStanzaSent), 110: wait_for_counter(StanzaReceived + 1, xmppStanzaReceived) 111: 112: end). 113: 114: presence_one(Config) -> 115: escalus:story(Config, [{alice, 1}], fun(Alice) -> 116: {value, PresenceSent} = get_counter_value(xmppPresenceSent), 117: {value, PresenceReceived} = get_counter_value(xmppPresenceReceived), 118: {value, StanzaSent} = get_counter_value(xmppStanzaSent), 119: {value, StanzaReceived} = get_counter_value(xmppStanzaReceived), 120: 121: escalus:send(Alice, escalus_stanza:presence(<<"available">>)), 122: escalus:wait_for_stanza(Alice), 123: 124: wait_for_counter(PresenceSent + 1, xmppPresenceSent), 125: wait_for_counter(PresenceReceived + 1, xmppPresenceReceived), 126: wait_for_counter(StanzaSent + 1, xmppStanzaSent), 127: wait_for_counter(StanzaReceived + 1, xmppStanzaReceived) 128: 129: end). 130: 131: presence_direct_one(Config) -> 132: escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> 133: {value, PresenceSent} = get_counter_value(xmppPresenceSent), 134: {value, PresenceReceived} = get_counter_value(xmppPresenceReceived), 135: {value, StanzaSent} = get_counter_value(xmppStanzaSent), 136: {value, StanzaReceived} = get_counter_value(xmppStanzaReceived), 137: 138: Presence = escalus_stanza:presence_direct(escalus_client:short_jid(Bob), <<"available">>), 139: escalus:send(Alice, Presence), 140: escalus:wait_for_stanza(Bob), 141: 142: wait_for_counter(PresenceSent + 1, xmppPresenceSent), 143: wait_for_counter(PresenceReceived + 1, xmppPresenceReceived), 144: wait_for_counter(StanzaSent + 1, xmppStanzaSent), 145: wait_for_counter(StanzaReceived + 1, xmppStanzaReceived) 146: 147: end). 148: 149: iq_one(Config) -> 150: escalus:story(Config, [{alice, 1}], fun(Alice) -> 151: {value, IqSent} = get_counter_value(xmppIqSent), 152: {value, IqReceived} = get_counter_value(xmppIqReceived), 153: {value, StanzaSent} = get_counter_value(xmppStanzaSent), 154: {value, StanzaReceived} = get_counter_value(xmppStanzaReceived), 155: 156: escalus_client:send(Alice, 157: escalus_stanza:roster_get()), 158: escalus_client:wait_for_stanza(Alice), 159: 160: wait_for_counter(IqSent + 1, xmppIqSent), 161: wait_for_counter(StanzaSent + 1, xmppStanzaSent), 162: wait_for_counter(StanzaReceived + 1, xmppStanzaReceived), 163: wait_for_counter(IqReceived + 1, xmppIqReceived) 164: 165: end). 166: 167: messages(Config) -> 168: {value, MesgSent} = get_counter_value(xmppMessageSent), 169: {value, MesgReceived} = get_counter_value(xmppMessageReceived), 170: escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> 171: 172: escalus_client:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi!">>)), 173: escalus_client:wait_for_stanza(Bob), 174: escalus_client:send(Bob, escalus_stanza:chat_to(Alice, <<"Hi!">>)), 175: escalus_client:wait_for_stanza(Alice), 176: escalus_client:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi!">>)), 177: escalus_client:wait_for_stanza(Bob), 178: escalus_client:send(Bob, escalus_stanza:chat_to(Alice, <<"Hi!">>)), 179: escalus_client:wait_for_stanza(Alice), 180: 181: wait_for_counter(MesgSent + 4, xmppMessageSent), 182: wait_for_counter(MesgReceived + 4, xmppMessageReceived) 183: 184: end). 185: 186: bounced(Config) -> 187: {value, MesgBounced} = get_counter_value(xmppMessageBounced), 188: escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> 189: 190: escalus_client:stop(Config, Bob), 191: timer:sleep(?WAIT_TIME), 192: 193: escalus_client:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi!">>)), 194: wait_for_counter(MesgBounced + 1, xmppMessageBounced) 195: 196: end). 197: 198: stanza_count(Config) -> 199: escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> 200: {value, OldStanzaCount} = get_counter_value(xmppStanzaCount), 201: 202: escalus_client:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi!">>)), 203: escalus_client:wait_for_stanza(Bob), 204: escalus_client:send(Bob, escalus_stanza:chat_to(Alice, <<"Hi!">>)), 205: escalus_client:wait_for_stanza(Alice), 206: escalus_client:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi!">>)), 207: escalus_client:wait_for_stanza(Bob), 208: escalus_client:send(Bob, escalus_stanza:chat_to(Alice, <<"Hi!">>)), 209: escalus_client:wait_for_stanza(Alice), 210: 211: {value, StanzaCount} = get_counter_value(xmppStanzaCount), 212: true = StanzaCount >= OldStanzaCount + 4 213: 214: end). 215: 216: 217: %%----------------------------------------------------- 218: %% Error tests 219: %%----------------------------------------------------- 220: 221: error_total(Config) -> 222: {value, Errors} = get_counter_value(xmppErrorTotal), 223: escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> 224: 225: escalus_client:stop(Config, Bob), 226: timer:sleep(?WAIT_TIME), 227: 228: escalus_client:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi!">>)), 229: wait_for_counter(Errors + 1, xmppErrorTotal) 230: 231: end). 232: 233: error_mesg(Config) -> 234: {value, Errors} = get_counter_value(xmppErrorMessage), 235: escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> 236: 237: escalus_client:stop(Config, Bob), 238: timer:sleep(?WAIT_TIME), 239: 240: escalus_client:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi!">>)), 241: wait_for_counter(Errors + 1, xmppErrorMessage) 242: 243: end). 244: 245: error_presence(Config) -> 246: {value, Errors} = get_counter_value(xmppErrorPresence), 247: escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) -> 248: 249: escalus:send(Alice, escalus_stanza:presence_direct( 250: escalus_client:short_jid(Bob), <<"available">>)), 251: escalus:wait_for_stanza(Bob), 252: 253: ErrorElt = escalus_stanza:error_element(<<"cancel">>, <<"gone">>), 254: Presence = escalus_stanza:presence_direct(escalus_client:short_jid(Alice), 255: <<"error">>, [ErrorElt]), 256: escalus:send(Bob, Presence), 257: 258: wait_for_counter(Errors + 1, xmppErrorPresence) 259: 260: end). 261: 262: error_iq(Config) -> 263: {value, Errors} = get_counter_value(xmppErrorIq), 264: 265: Users = escalus_config:get_config(escalus_users, Config), 266: Alice = escalus_users:get_user_by_name(alice, Users), 267: escalus_users:create_user(Config, Alice), 268: wait_for_counter(Errors + 1, xmppErrorIq).