2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
11 local st = require "util.stanza";
12 local register_component = require "core.componentmanager".register_component;
13 local core_route_stanza = core_route_stanza;
14 local socket = require "socket";
15 local config = require "core.configmanager";
16 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" };
18 local open_pings = {};
20 local t_insert = table.insert;
22 local log = require "util.logger".init("mod_selftests");
24 local tests_jid = "self_tests@getjabber.ath.cx";
25 local host = "getjabber.ath.cx";
27 if not (tests_jid and host) then
28 for currhost in pairs(host) do
29 if currhost ~= "localhost" then
30 tests_jid, host = "self_tests@"..currhost, currhost;
35 if tests_jid and host then
36 local bot = register_component(tests_jid, function(origin, stanza, ourhost)
37 local time = open_pings[stanza.attr.id];
40 log("info", "Ping reply from %s in %fs", tostring(stanza.attr.from), socket.gettime() - time);
42 log("info", "Unexpected reply: %s", stanza:pretty_print());
47 local our_origin = hosts[host];
48 module:add_event_hook("server-started",
50 local id = st.new_id();
51 local ping_attr = { xmlns = 'urn:xmpp:ping' };
52 local function send_ping(to)
53 log("info", "Sending ping to %s", to);
54 core_route_stanza(our_origin, st.iq{ to = to, from = tests_jid, id = id, type = "get" }:tag("ping", ping_attr));
55 open_pings[id] = socket.gettime();
58 for _, host in ipairs(ping_hosts) do