From 902d98e4865d92ebeea81c0ddcb5a38fa63d1162 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 20 Nov 2008 22:42:37 +0000 Subject: Adding selftests module, but not enabling in config --- plugins/mod_selftests.lua | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 plugins/mod_selftests.lua (limited to 'plugins/mod_selftests.lua') diff --git a/plugins/mod_selftests.lua b/plugins/mod_selftests.lua new file mode 100644 index 00000000..fe09e529 --- /dev/null +++ b/plugins/mod_selftests.lua @@ -0,0 +1,57 @@ + +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 open_pings = {}; + +local t_insert = table.insert; + +local log = require "util.logger".init("mod_selftests"); + +local tests_jid, host; "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 + + send_ping "matthewwild.co.uk" + send_ping "snikket.com" + send_ping "gmail.com" + send_ping "isode.com" + send_ping "jabber.org" + send_ping "chrome.pl" + send_ping "swissjabber.ch" + send_ping "soapbox.net" + send_ping "jabber.ccc.de" + end); +end -- cgit v1.2.3 From a7b3157e9ff6d26b7218931646f6e02ed6063be8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 23 Nov 2008 02:11:58 +0000 Subject: Fix mod_selftests syntax, and switch it to use config --- plugins/mod_selftests.lua | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'plugins/mod_selftests.lua') diff --git a/plugins/mod_selftests.lua b/plugins/mod_selftests.lua index fe09e529..4f128504 100644 --- a/plugins/mod_selftests.lua +++ b/plugins/mod_selftests.lua @@ -3,6 +3,8 @@ 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 = {}; @@ -10,7 +12,7 @@ local t_insert = table.insert; local log = require "util.logger".init("mod_selftests"); -local tests_jid, host; "self_tests@getjabber.ath.cx"; +local tests_jid = "self_tests@getjabber.ath.cx"; local host = "getjabber.ath.cx"; if not (tests_jid and host) then @@ -44,14 +46,8 @@ if tests_jid and host then open_pings[id] = socket.gettime(); end - send_ping "matthewwild.co.uk" - send_ping "snikket.com" - send_ping "gmail.com" - send_ping "isode.com" - send_ping "jabber.org" - send_ping "chrome.pl" - send_ping "swissjabber.ch" - send_ping "soapbox.net" - send_ping "jabber.ccc.de" + for _, host in ipairs(ping_hosts) do + send_ping(host); + end end); end -- cgit v1.2.3