scansion/objects/client.lua

Sun, 30 Dec 2018 09:43:36 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 30 Dec 2018 09:43:36 +0000
changeset 164
14500a149b31
parent 130
ce99abde467b
child 171
433a1f36d0d3
permissions
-rw-r--r--

client: Ignore timeout timer if we received a stanza

8
42b4e73c0d30 client: Wait for login to complete before continuing past the 'connects' action
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
1 local async = require "scansion.async";
66
909c00296c2a client: Make use of new scansion.error library, log the received stanza when different to expected one
Matthew Wild <mwild1@gmail.com>
parents: 60
diff changeset
2 local new_error = require "scansion.error".new_error;
4
c54194d8cc30 client: verse improvements
Matthew Wild <mwild1@gmail.com>
parents: 1
diff changeset
3 local verse = require "verse".init("client");
1
017c5809d537 client: Enable verse log output
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
4
0
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local parse_xml = require "scansion.xml".parse;
6
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
6
82
f90056b8e278 main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents: 73
diff changeset
7 local default_stanza_timeout = 3;
6
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
8
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
9 local stanzacmp = require "scansion.stanzacmp";
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
10
37
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
11 local function filter_expression(script, s)
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
12 local expr = s:match("^%$%{(.+)%}$");
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
13 if not expr then return s end
46
Matthew Wild <mwild1@gmail.com>
parents: 44 38
diff changeset
14 local name, value_name = expr:match("^(.+)'s (.+)$");
37
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
15 assert(name, "Unable to parse expression: "..expr);
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
16 local key = value_name:lower():gsub(" ", "_");
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
17 assert(script.objects[name], "Unknown object called "..name);
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
18 local value = script.objects[name][key];
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
19 assert(value ~= nil, "Unknown attribute (of "..name.."): "..value_name);
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
20 return value;
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
21 end
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
22
16
59f176aa3465 client: Allow simple variable substitution in XML in scripts
Matthew Wild <mwild1@gmail.com>
parents: 15
diff changeset
23 local function fill_vars(script, stanza)
59f176aa3465 client: Allow simple variable substitution in XML in scripts
Matthew Wild <mwild1@gmail.com>
parents: 15
diff changeset
24 for k, v in pairs(stanza.attr) do
37
b2036129ccd0 client: Split variable expansion into a function so that it may be reused more easily
Kim Alvefur <zash@zash.se>
parents: 34
diff changeset
25 stanza.attr[k] = filter_expression(script, v);
16
59f176aa3465 client: Allow simple variable substitution in XML in scripts
Matthew Wild <mwild1@gmail.com>
parents: 15
diff changeset
26 end
38
68458d0c50a0 client: Apply variable expansion to text nodes
Kim Alvefur <zash@zash.se>
parents: 37
diff changeset
27 for i, child in ipairs(stanza) do
68458d0c50a0 client: Apply variable expansion to text nodes
Kim Alvefur <zash@zash.se>
parents: 37
diff changeset
28 if type(child) == "string" then
68458d0c50a0 client: Apply variable expansion to text nodes
Kim Alvefur <zash@zash.se>
parents: 37
diff changeset
29 stanza[i] = filter_expression(script, child);
68458d0c50a0 client: Apply variable expansion to text nodes
Kim Alvefur <zash@zash.se>
parents: 37
diff changeset
30 elseif type(child) == "table" then
68458d0c50a0 client: Apply variable expansion to text nodes
Kim Alvefur <zash@zash.se>
parents: 37
diff changeset
31 fill_vars(script, child);
68458d0c50a0 client: Apply variable expansion to text nodes
Kim Alvefur <zash@zash.se>
parents: 37
diff changeset
32 end
34
946c7d13faac client: Apply variable expansion recursively to child nodes
Kim Alvefur <zash@zash.se>
parents: 29
diff changeset
33 end
16
59f176aa3465 client: Allow simple variable substitution in XML in scripts
Matthew Wild <mwild1@gmail.com>
parents: 15
diff changeset
34 return stanza;
59f176aa3465 client: Allow simple variable substitution in XML in scripts
Matthew Wild <mwild1@gmail.com>
parents: 15
diff changeset
35 end
59f176aa3465 client: Allow simple variable substitution in XML in scripts
Matthew Wild <mwild1@gmail.com>
parents: 15
diff changeset
36
0
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 return {
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 _validate = function (client)
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 assert(client.jid, "No JID specified");
23
af7a51d78b7b client: Improve stream logging, now prefixed by client name (taken from script)
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
40 client.stream = verse.new(verse.new_logger(client.name));
48
6450aea6c564 scansion.objects.client: Pass on 'connect_host' to the stream
Kim Alvefur <zash@zash.se>
parents: 46
diff changeset
41 client.stream.connect_host = client.connect_host
49
69c329681c3b scansion.objects.client: And the port too
Kim Alvefur <zash@zash.se>
parents: 48
diff changeset
42 client.stream.connect_port = client.connect_port
23
af7a51d78b7b client: Improve stream logging, now prefixed by client name (taken from script)
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
43
af7a51d78b7b client: Improve stream logging, now prefixed by client name (taken from script)
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
44 function client.log(fmt, ...)
af7a51d78b7b client: Improve stream logging, now prefixed by client name (taken from script)
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
45 return client.stream:info(fmt, ...);
af7a51d78b7b client: Improve stream logging, now prefixed by client name (taken from script)
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
46 end
10
75bf4c021461 client: ALL the debugging on
Matthew Wild <mwild1@gmail.com>
parents: 8
diff changeset
47
75bf4c021461 client: ALL the debugging on
Matthew Wild <mwild1@gmail.com>
parents: 8
diff changeset
48 -- This one prints all received data
23
af7a51d78b7b client: Improve stream logging, now prefixed by client name (taken from script)
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
49 client.stream:hook("incoming-raw", function (s) client.log("Data in: %s", s); end, 1000);
af7a51d78b7b client: Improve stream logging, now prefixed by client name (taken from script)
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
50 client.stream:hook("outgoing-raw", function (s) client.log("Data out: %s", s); end, 1000);
af7a51d78b7b client: Improve stream logging, now prefixed by client name (taken from script)
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
51 -- And incoming, parsed, stanzas
af7a51d78b7b client: Improve stream logging, now prefixed by client name (taken from script)
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
52 client.stream:hook("stanza", function (s) client.log("Stanza: %s", s) end);
60
e032cdb517ab client.lua: Handle unexpected disconnects in the middle of a test
Matthew Wild <mwild1@gmail.com>
parents: 53
diff changeset
53 -- Handle unexpected disconnects
e032cdb517ab client.lua: Handle unexpected disconnects in the middle of a test
Matthew Wild <mwild1@gmail.com>
parents: 53
diff changeset
54 client.stream:hook("disconnected", function (s)
118
073136acfeab client: Add _finish handler to disconnect from server if still connected
Matthew Wild <mwild1@gmail.com>
parents: 111
diff changeset
55 if not (client.disconnect_expected or client.script.finished) or (s.reason and s.reason ~= "stream closed" and s.reason ~= "closed") then
90
8458f8bdb3b0 client: Detect unexpected disconnects more reliably
Matthew Wild <mwild1@gmail.com>
parents: 84
diff changeset
56 client.log("Unexpected disconnect!");
8458f8bdb3b0 client: Detect unexpected disconnects more reliably
Matthew Wild <mwild1@gmail.com>
parents: 84
diff changeset
57 error("Unexpected disconnect"..(s.reason and " ("..tostring(s.reason)..")" or ""));
8458f8bdb3b0 client: Detect unexpected disconnects more reliably
Matthew Wild <mwild1@gmail.com>
parents: 84
diff changeset
58 end
60
e032cdb517ab client.lua: Handle unexpected disconnects in the middle of a test
Matthew Wild <mwild1@gmail.com>
parents: 53
diff changeset
59 end);
0
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 end;
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61
118
073136acfeab client: Add _finish handler to disconnect from server if still connected
Matthew Wild <mwild1@gmail.com>
parents: 111
diff changeset
62 _finish = function (client)
073136acfeab client: Add _finish handler to disconnect from server if still connected
Matthew Wild <mwild1@gmail.com>
parents: 111
diff changeset
63 if client.stream.connected then
073136acfeab client: Add _finish handler to disconnect from server if still connected
Matthew Wild <mwild1@gmail.com>
parents: 111
diff changeset
64 client.disconnect_expected = true;
073136acfeab client: Add _finish handler to disconnect from server if still connected
Matthew Wild <mwild1@gmail.com>
parents: 111
diff changeset
65 client.stream:close();
073136acfeab client: Add _finish handler to disconnect from server if still connected
Matthew Wild <mwild1@gmail.com>
parents: 111
diff changeset
66 end
073136acfeab client: Add _finish handler to disconnect from server if still connected
Matthew Wild <mwild1@gmail.com>
parents: 111
diff changeset
67 end;
073136acfeab client: Add _finish handler to disconnect from server if still connected
Matthew Wild <mwild1@gmail.com>
parents: 111
diff changeset
68
0
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 connects = function (client)
8
42b4e73c0d30 client: Wait for login to complete before continuing past the 'connects' action
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
70 local wait, done = async.waiter();
52
3eedbb76e3f2 scansion.objects.client: Split long line into one statement per line
Kim Alvefur <zash@zash.se>
parents: 51
diff changeset
71 client.stream:hook("ready", function ()
53
3208dff3fb31 scansion.objects.client: Pause connection before resuming async processing
Kim Alvefur <zash@zash.se>
parents: 52
diff changeset
72 client.stream.conn:pause()
52
3eedbb76e3f2 scansion.objects.client: Split long line into one statement per line
Kim Alvefur <zash@zash.se>
parents: 51
diff changeset
73 client.log"ready"
3eedbb76e3f2 scansion.objects.client: Split long line into one statement per line
Kim Alvefur <zash@zash.se>
parents: 51
diff changeset
74 done()
3eedbb76e3f2 scansion.objects.client: Split long line into one statement per line
Kim Alvefur <zash@zash.se>
parents: 51
diff changeset
75 client.log("ready done")
3eedbb76e3f2 scansion.objects.client: Split long line into one statement per line
Kim Alvefur <zash@zash.se>
parents: 51
diff changeset
76 end);
4
c54194d8cc30 client: verse improvements
Matthew Wild <mwild1@gmail.com>
parents: 1
diff changeset
77 client.stream:connect_client(client.jid, client.password);
8
42b4e73c0d30 client: Wait for login to complete before continuing past the 'connects' action
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
78 wait();
15
0441673df075 client: Add full JID as property of clients
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
79 client.full_jid = client.stream.jid;
50
0ce9c9a0c2a0 scansion.objects.client: Expose a 'host' property with the bare hostname
Kim Alvefur <zash@zash.se>
parents: 49
diff changeset
80 client.host = client.stream.host;
0
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 end;
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 sends = function (client, data)
24
3c572d238d9e client: More flexible handling of whitespace in stanzas in script
Matthew Wild <mwild1@gmail.com>
parents: 23
diff changeset
84 local stanza = fill_vars(client.script, assert(parse_xml((table.concat(data):gsub("\t", " ")))));
73
1c07ef6c6502 client: Wait for 'drained' event when sending stanzas (experimental, may help with syncing to server's logs)
Matthew Wild <mwild1@gmail.com>
parents: 66
diff changeset
85 local wait, done = async.waiter();
1c07ef6c6502 client: Wait for 'drained' event when sending stanzas (experimental, may help with syncing to server's logs)
Matthew Wild <mwild1@gmail.com>
parents: 66
diff changeset
86 local function handle_drained()
1c07ef6c6502 client: Wait for 'drained' event when sending stanzas (experimental, may help with syncing to server's logs)
Matthew Wild <mwild1@gmail.com>
parents: 66
diff changeset
87 client.stream:unhook("drained", handle_drained);
1c07ef6c6502 client: Wait for 'drained' event when sending stanzas (experimental, may help with syncing to server's logs)
Matthew Wild <mwild1@gmail.com>
parents: 66
diff changeset
88 done();
1c07ef6c6502 client: Wait for 'drained' event when sending stanzas (experimental, may help with syncing to server's logs)
Matthew Wild <mwild1@gmail.com>
parents: 66
diff changeset
89 end
1c07ef6c6502 client: Wait for 'drained' event when sending stanzas (experimental, may help with syncing to server's logs)
Matthew Wild <mwild1@gmail.com>
parents: 66
diff changeset
90 client.stream:hook("drained", handle_drained);
6
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
91 client.stream:send(stanza);
73
1c07ef6c6502 client: Wait for 'drained' event when sending stanzas (experimental, may help with syncing to server's logs)
Matthew Wild <mwild1@gmail.com>
parents: 66
diff changeset
92 wait();
0
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 end;
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 receives = function (client, data)
26
c32334d33438 client: Wait for received stanzas using async waiter
Matthew Wild <mwild1@gmail.com>
parents: 25
diff changeset
96 local wait, done = async.waiter();
84
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
97 local expected_stanza = false;
164
14500a149b31 client: Ignore timeout timer if we received a stanza
Matthew Wild <mwild1@gmail.com>
parents: 130
diff changeset
98 local have_received_stanza = false;
84
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
99 data = table.concat(data):gsub("\t", " "):gsub("^%s+", ""):gsub("%s+$", "");
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
100 if data ~= "nothing" then
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
101 expected_stanza = fill_vars(client.script, assert(parse_xml(data)));
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
102 end
6
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
103 local function stanza_handler(received_stanza)
164
14500a149b31 client: Ignore timeout timer if we received a stanza
Matthew Wild <mwild1@gmail.com>
parents: 130
diff changeset
104 have_received_stanza = true;
84
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
105 if not expected_stanza then
111
25530dccf696 scansion.error, client: Change error syntax slightly, so first param is identifier string
Matthew Wild <mwild1@gmail.com>
parents: 105
diff changeset
106 error(new_error("unexpected-stanza", {
25530dccf696 scansion.error, client: Change error syntax slightly, so first param is identifier string
Matthew Wild <mwild1@gmail.com>
parents: 105
diff changeset
107 text = "Received unexpected stanza";
25530dccf696 scansion.error, client: Change error syntax slightly, so first param is identifier string
Matthew Wild <mwild1@gmail.com>
parents: 105
diff changeset
108 stanza = tostring(received_stanza);
25530dccf696 scansion.error, client: Change error syntax slightly, so first param is identifier string
Matthew Wild <mwild1@gmail.com>
parents: 105
diff changeset
109 }));
84
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
110 elseif not expected_stanza or not stanzacmp.stanzas_match(expected_stanza, received_stanza) then
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
111 if not expected_stanza then
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
112 client.log("Received a stanza when none were expected: %s", received_stanza);
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
113 else
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
114 client.log("Expected: %s", expected_stanza);
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
115 client.log("Received: %s", received_stanza);
c9061cd9951b client: Support for "receives: nothing", to verify that the server does not respond to a given stanza, for example
Matthew Wild <mwild1@gmail.com>
parents: 83
diff changeset
116 end
111
25530dccf696 scansion.error, client: Change error syntax slightly, so first param is identifier string
Matthew Wild <mwild1@gmail.com>
parents: 105
diff changeset
117 error(new_error("unexpected-stanza", {
25530dccf696 scansion.error, client: Change error syntax slightly, so first param is identifier string
Matthew Wild <mwild1@gmail.com>
parents: 105
diff changeset
118 text = "Received unexpected stanza";
105
da98bb33cee6 scansion.objects.client: Include expected stanza in error, if any
Matthew Wild <mwild1@gmail.com>
parents: 90
diff changeset
119 stanza = tostring(received_stanza);
da98bb33cee6 scansion.objects.client: Include expected stanza in error, if any
Matthew Wild <mwild1@gmail.com>
parents: 90
diff changeset
120 expected = expected_stanza and tostring(expected_stanza) or nil;
da98bb33cee6 scansion.objects.client: Include expected stanza in error, if any
Matthew Wild <mwild1@gmail.com>
parents: 90
diff changeset
121 }));
6
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
122 else
83
52f8fa7f999e client: Store last received id so it can be used in scripts
Matthew Wild <mwild1@gmail.com>
parents: 82
diff changeset
123 client.last_received_id = received_stanza.attr.id;
23
af7a51d78b7b client: Improve stream logging, now prefixed by client name (taken from script)
Matthew Wild <mwild1@gmail.com>
parents: 22
diff changeset
124 client.log("YES! %s", expected_stanza)
6
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
125 end
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
126 expected_stanza = nil;
27
34d405303242 client: Remove stanza handler when stanza comes in
Matthew Wild <mwild1@gmail.com>
parents: 26
diff changeset
127 client.stream:unhook("stanza", stanza_handler);
51
afc7765827be scansion.objects.client: Hold of reading from clients when they are not expecting stanzas
Kim Alvefur <zash@zash.se>
parents: 50
diff changeset
128 client.stream.conn:pause();
90
8458f8bdb3b0 client: Detect unexpected disconnects more reliably
Matthew Wild <mwild1@gmail.com>
parents: 84
diff changeset
129 client.log("Calling done")
26
c32334d33438 client: Wait for received stanzas using async waiter
Matthew Wild <mwild1@gmail.com>
parents: 25
diff changeset
130 done();
6
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
131 end
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
132 client.stream:hook("stanza", stanza_handler, 100);
82
f90056b8e278 main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents: 73
diff changeset
133 verse.add_task(client.stanza_timeout or default_stanza_timeout, function ()
164
14500a149b31 client: Ignore timeout timer if we received a stanza
Matthew Wild <mwild1@gmail.com>
parents: 130
diff changeset
134 if have_received_stanza then return; end
82
f90056b8e278 main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents: 73
diff changeset
135 if expected_stanza then
f90056b8e278 main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents: 73
diff changeset
136 client.log("TIMEOUT waiting for %s", expected_stanza)
130
ce99abde467b client: Throw scansion error on stanza timeout, to avoid traceback
Matthew Wild <mwild1@gmail.com>
parents: 118
diff changeset
137 local e = new_error("stanza-timeout", { text = "Timed out waiting for stanza" });
ce99abde467b client: Throw scansion error on stanza timeout, to avoid traceback
Matthew Wild <mwild1@gmail.com>
parents: 118
diff changeset
138 error(e);
82
f90056b8e278 main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents: 73
diff changeset
139 end
f90056b8e278 main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents: 73
diff changeset
140 if expected_stanza == false then
f90056b8e278 main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents: 73
diff changeset
141 client.log("Good - no stanzas were received (expected)");
f90056b8e278 main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents: 73
diff changeset
142 done();
f90056b8e278 main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them
Matthew Wild <mwild1@gmail.com>
parents: 73
diff changeset
143 end
6
0c94ea0cabec client: Implement send/receive, including new stanzacmp library
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
144 end);
51
afc7765827be scansion.objects.client: Hold of reading from clients when they are not expecting stanzas
Kim Alvefur <zash@zash.se>
parents: 50
diff changeset
145 client.stream.conn:resume();
26
c32334d33438 client: Wait for received stanzas using async waiter
Matthew Wild <mwild1@gmail.com>
parents: 25
diff changeset
146 wait();
0
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 end;
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 disconnects = function (client)
90
8458f8bdb3b0 client: Detect unexpected disconnects more reliably
Matthew Wild <mwild1@gmail.com>
parents: 84
diff changeset
150 client.disconnect_expected = true;
29
9dcdea04601c client: Implement 'disconnects' action
Matthew Wild <mwild1@gmail.com>
parents: 28
diff changeset
151 client.stream:close();
0
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 end;
2e31b584f8d9 It is better to write and run incomplete tests than not to run complete tests. -- Martin Fowler
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 }

mercurial