Software /
code /
prosody
Annotate
plugins/mod_selftests.lua @ 364:02b8f2ffa6a7
Adding selftests module, but not enabling in config
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 20 Nov 2008 22:42:37 +0000 |
child | 375:a6a4ea3633b0 |
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"; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local open_pings = {}; |
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 t_insert = table.insert; |
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 log = require "util.logger".init("mod_selftests"); |
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 tests_jid, host; "self_tests@getjabber.ath.cx"; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local host = "getjabber.ath.cx"; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 if not (tests_jid and host) then |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 for currhost in pairs(host) do |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 if currhost ~= "localhost" then |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 tests_jid, host = "self_tests@"..currhost, currhost; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 end |
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 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 if tests_jid and host then |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 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
|
26 local time = open_pings[stanza.attr.id]; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 if time then |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 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
|
30 else |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 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
|
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 |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local our_origin = hosts[host]; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 add_event_hook("server-started", |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 function () |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local id = st.new_id(); |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 local ping_attr = { xmlns = 'urn:xmpp:ping' }; |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 local function send_ping(to) |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 log("info", "Sending ping to %s", to); |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 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
|
44 open_pings[id] = socket.gettime(); |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 end |
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 send_ping "matthewwild.co.uk" |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 send_ping "snikket.com" |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 send_ping "gmail.com" |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 send_ping "isode.com" |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 send_ping "jabber.org" |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 send_ping "chrome.pl" |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 send_ping "swissjabber.ch" |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 send_ping "soapbox.net" |
02b8f2ffa6a7
Adding selftests module, but not enabling in config
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 send_ping "jabber.ccc.de" |
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 end |