Software /
code /
prosody
Annotate
plugins/mod_selftests.lua @ 1646:21bcc7b8b4d8
mod_version: Rewritten to use new API. Added reply caching, and fixed some issues.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 07 Aug 2009 18:29:14 +0500 |
parent | 1523:841d61be198f |
child | 1651:6954d8f314a1 |
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 | 5 -- This project is MIT/X11 licensed. Please see the |
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 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
9 |
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"; |
375
a6a4ea3633b0
Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents:
364
diff
changeset
|
15 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
|
16 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
|
17 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local open_pings = {}; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local t_insert = table.insert; |
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 log = require "util.logger".init("mod_selftests"); |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
375
a6a4ea3633b0
Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents:
364
diff
changeset
|
24 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
|
25 local host = "getjabber.ath.cx"; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 if not (tests_jid and host) then |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 for currhost in pairs(host) do |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 if currhost ~= "localhost" then |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 tests_jid, host = "self_tests@"..currhost, currhost; |
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 end |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 if tests_jid and host then |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 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
|
37 local time = open_pings[stanza.attr.id]; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 if time then |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 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
|
41 else |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 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
|
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 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 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
|
48 module:add_event_hook("server-started", |
364
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 function () |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 local id = st.new_id(); |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 local ping_attr = { xmlns = 'urn:xmpp:ping' }; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 local function send_ping(to) |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 log("info", "Sending ping to %s", to); |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 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
|
55 open_pings[id] = socket.gettime(); |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 end |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 |
375
a6a4ea3633b0
Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents:
364
diff
changeset
|
58 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
|
59 send_ping(host); |
a6a4ea3633b0
Fix mod_selftests syntax, and switch it to use config
Matthew Wild <mwild1@gmail.com>
parents:
364
diff
changeset
|
60 end |
364
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 end); |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |