2 -- Copyright (C) 2008 Matthew Wild
3 -- Copyright (C) 2008 Waqas Hussain
5 -- This program is free software; you can redistribute it and/or
6 -- modify it under the terms of the GNU General Public License
7 -- as published by the Free Software Foundation; either version 2
8 -- of the License, or (at your option) any later version.
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 local st = require "util.stanza";
23 local register_component = require "core.componentmanager".register_component;
24 local core_route_stanza = core_route_stanza;
25 local socket = require "socket";
26 local config = require "core.configmanager";
27 local ping_hosts = config.get("*", "mod_selftests", "ping_hosts") or { "coversant.interop.xmpp.org", "djabberd.interop.xmpp.org", "djabberd-trunk.interop.xmpp.org", "ejabberd.interop.xmpp.org", "openfire.interop.xmpp.org" };
29 local open_pings = {};
31 local t_insert = table.insert;
33 local log = require "util.logger".init("mod_selftests");
35 local tests_jid = "self_tests@getjabber.ath.cx";
36 local host = "getjabber.ath.cx";
38 if not (tests_jid and host) then
39 for currhost in pairs(host) do
40 if currhost ~= "localhost" then
41 tests_jid, host = "self_tests@"..currhost, currhost;
46 if tests_jid and host then
47 local bot = register_component(tests_jid, function(origin, stanza, ourhost)
48 local time = open_pings[stanza.attr.id];
51 log("info", "Ping reply from %s in %fs", tostring(stanza.attr.from), socket.gettime() - time);
53 log("info", "Unexpected reply: %s", stanza:pretty_print());
58 local our_origin = hosts[host];
59 module:add_event_hook("server-started",
61 local id = st.new_id();
62 local ping_attr = { xmlns = 'urn:xmpp:ping' };
63 local function send_ping(to)
64 log("info", "Sending ping to %s", to);
65 core_route_stanza(our_origin, st.iq{ to = to, from = tests_jid, id = id, type = "get" }:tag("ping", ping_attr));
66 open_pings[id] = socket.gettime();
69 for _, host in ipairs(ping_hosts) do