Annotate

plugins/mod_selftests.lua @ 584:eb0cea29c8d7

Temporary hack for global modules
author Matthew Wild <mwild1@gmail.com>
date Sat, 06 Dec 2008 23:15:48 +0000
parent 519:cccd610a0ef9
child 615:4ae3e81513f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
1 -- Prosody IM v0.1
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
2 -- Copyright (C) 2008 Matthew Wild
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
3 -- Copyright (C) 2008 Waqas Hussain
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
4 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
5 -- This program is free software; you can redistribute it and/or
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
6 -- modify it under the terms of the GNU General Public License
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
7 -- as published by the Free Software Foundation; either version 2
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
8 -- of the License, or (at your option) any later version.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
9 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
10 -- This program is distributed in the hope that it will be useful,
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
13 -- GNU General Public License for more details.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
14 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
15 -- You should have received a copy of the GNU General Public License
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
16 -- along with this program; if not, write to the Free Software
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
18 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
19
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
20
364
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local st = require "util.stanza";
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 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
24 local core_route_stanza = core_route_stanza;
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 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
26 local config = require "core.configmanager";
428
e717ecc97d2e Update mod_selftests to use the hosts on http://xmpp.org/interop/servers.shtml
Matthew Wild <mwild1@gmail.com>
parents: 375
diff changeset
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" };
364
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 local open_pings = {};
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 local t_insert = table.insert;
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 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
34
375
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
35 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
36 local host = "getjabber.ath.cx";
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 if not (tests_jid and host) then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 for currhost in pairs(host) do
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 if currhost ~= "localhost" then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 tests_jid, host = "self_tests@"..currhost, currhost;
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 if tests_jid and host then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 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
48 local time = open_pings[stanza.attr.id];
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 if time then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 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
52 else
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 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
54 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 end);
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 local our_origin = hosts[host];
438
193f9dd64f17 Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents: 428
diff changeset
59 module:add_event_hook("server-started",
364
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 function ()
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 local id = st.new_id();
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 local ping_attr = { xmlns = 'urn:xmpp:ping' };
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 local function send_ping(to)
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 log("info", "Sending ping to %s", to);
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 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
66 open_pings[id] = socket.gettime();
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68
375
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
69 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
70 send_ping(host);
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
71 end
364
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 end);
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 end