aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_selftests.lua
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2008-11-23 20:44:48 +0100
committerTobias Markmann <tm@ayena.de>2008-11-23 20:44:48 +0100
commit560094822d86f10450567785544cfcca61dd8a3b (patch)
treec2737280276b8ec3642cae5ae644e81da621be04 /plugins/mod_selftests.lua
parent3bc6fdb526dec6b56dab9208461d5b2f4db08006 (diff)
parent6db47b60f4574bc8e5a34eacac8a67ccd52107dd (diff)
downloadprosody-560094822d86f10450567785544cfcca61dd8a3b.tar.gz
prosody-560094822d86f10450567785544cfcca61dd8a3b.zip
Merging with main branch.
Diffstat (limited to 'plugins/mod_selftests.lua')
-rw-r--r--plugins/mod_selftests.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/mod_selftests.lua b/plugins/mod_selftests.lua
new file mode 100644
index 00000000..4f128504
--- /dev/null
+++ b/plugins/mod_selftests.lua
@@ -0,0 +1,53 @@
+
+local st = require "util.stanza";
+local register_component = require "core.componentmanager".register_component;
+local core_route_stanza = core_route_stanza;
+local socket = require "socket";
+local config = require "core.configmanager";
+local ping_hosts = config.get("*", "mod_selftests", "ping_hosts") or { "jabber.org" };
+
+local open_pings = {};
+
+local t_insert = table.insert;
+
+local log = require "util.logger".init("mod_selftests");
+
+local tests_jid = "self_tests@getjabber.ath.cx";
+local host = "getjabber.ath.cx";
+
+if not (tests_jid and host) then
+ for currhost in pairs(host) do
+ if currhost ~= "localhost" then
+ tests_jid, host = "self_tests@"..currhost, currhost;
+ end
+ end
+end
+
+if tests_jid and host then
+ local bot = register_component(tests_jid, function(origin, stanza, ourhost)
+ local time = open_pings[stanza.attr.id];
+
+ if time then
+ log("info", "Ping reply from %s in %fs", tostring(stanza.attr.from), socket.gettime() - time);
+ else
+ log("info", "Unexpected reply: %s", stanza:pretty_print());
+ end
+ end);
+
+
+ local our_origin = hosts[host];
+ add_event_hook("server-started",
+ function ()
+ local id = st.new_id();
+ local ping_attr = { xmlns = 'urn:xmpp:ping' };
+ local function send_ping(to)
+ log("info", "Sending ping to %s", to);
+ core_route_stanza(our_origin, st.iq{ to = to, from = tests_jid, id = id, type = "get" }:tag("ping", ping_attr));
+ open_pings[id] = socket.gettime();
+ end
+
+ for _, host in ipairs(ping_hosts) do
+ send_ping(host);
+ end
+ end);
+end