Annotate

plugins/mod_selftests.lua @ 1825:f67e4bfc62f1

MUC: Renamed a variable name.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 25 Sep 2009 12:36:11 +0500
parent 1653:02a55ad3dce1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
1 -- Prosody IM
760
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
6 -- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
7 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
8
1653
02a55ad3dce1 mod_selftests: Mark as global
Waqas Hussain <waqas20@gmail.com>
parents: 1651
diff changeset
9 module.host = "*" -- Global module
364
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 st = require "util.stanza";
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 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
13 local core_route_stanza = core_route_stanza;
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local socket = require "socket";
1651
6954d8f314a1 mod_selftests: Updated to use module:get_option instead of configmanager
Waqas Hussain <waqas20@gmail.com>
parents: 1523
diff changeset
15 local ping_hosts = module:get_option("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
16
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local open_pings = {};
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local t_insert = table.insert;
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 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
22
375
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
23 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
24 local host = "getjabber.ath.cx";
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 not (tests_jid and host) then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 for currhost in pairs(host) do
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 if currhost ~= "localhost" then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 tests_jid, host = "self_tests@"..currhost, currhost;
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 end
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 if tests_jid and host then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 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
36 local time = open_pings[stanza.attr.id];
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 time then
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 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
40 else
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 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
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
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 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
47 module:add_event_hook("server-started",
364
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 function ()
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 local id = st.new_id();
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 local ping_attr = { xmlns = 'urn:xmpp:ping' };
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 local function send_ping(to)
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 log("info", "Sending ping to %s", to);
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 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
54 open_pings[id] = socket.gettime();
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
375
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
57 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
58 send_ping(host);
a6a4ea3633b0 Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents: 364
diff changeset
59 end
364
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 end);
02b8f2ffa6a7 Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 end