Annotate

plugins/mod_selftests.lua @ 406:11f176cae9da

SSL library is optional, not a fatal error
author Matthew Wild <mwild1@gmail.com>
date Tue, 25 Nov 2008 01:55:01 +0000
parent 375:a6a4ea3633b0
child 428:e717ecc97d2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
364
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local st = require "util.stanza";
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local register_component = require "core.componentmanager".register_component;
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local core_route_stanza = core_route_stanza;
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local socket = require "socket";
375
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
6 local config = require "core.configmanager";
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
7 local ping_hosts = config.get("*", "mod_selftests", "ping_hosts") or { "jabber.org" };
364
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local open_pings = {};
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local t_insert = table.insert;
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local log = require "util.logger".init("mod_selftests");
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
375
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
15 local tests_jid = "self_tests@getjabber.ath.cx";
364
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local host = "getjabber.ath.cx";
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 if not (tests_jid and host) then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 for currhost in pairs(host) do
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 if currhost ~= "localhost" then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 tests_jid, host = "self_tests@"..currhost, currhost;
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 if tests_jid and host then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 local bot = register_component(tests_jid, function(origin, stanza, ourhost)
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 local time = open_pings[stanza.attr.id];
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 if time then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 log("info", "Ping reply from %s in %fs", tostring(stanza.attr.from), socket.gettime() - time);
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 else
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 log("info", "Unexpected reply: %s", stanza:pretty_print());
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 end);
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 local our_origin = hosts[host];
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 add_event_hook("server-started",
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 function ()
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 local id = st.new_id();
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 local ping_attr = { xmlns = 'urn:xmpp:ping' };
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 local function send_ping(to)
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 log("info", "Sending ping to %s", to);
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 core_route_stanza(our_origin, st.iq{ to = to, from = tests_jid, id = id, type = "get" }:tag("ping", ping_attr));
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 open_pings[id] = socket.gettime();
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48
375
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
49 for _, host in ipairs(ping_hosts) do
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
50 send_ping(host);
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
51 end
364
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end);
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 end