main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them

Fri, 19 Feb 2016 11:47:33 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 19 Feb 2016 11:47:33 +0000
changeset 82
f90056b8e278
parent 81
0ee626030acb
child 83
52f8fa7f999e

main.lua, client: Make timeouts more coherent (stanza timeout was greater than action timeout), add command-line options to change them

main.lua file | annotate | diff | comparison | revisions
scansion/objects/client.lua file | annotate | diff | comparison | revisions
--- a/main.lua	Thu Feb 18 19:02:28 2016 +0000
+++ b/main.lua	Fri Feb 19 11:47:33 2016 +0000
@@ -9,7 +9,7 @@
 local test_metadata = {};
 local server_log_wait_time = 0.2;
 local skip_server_startup_log = false;
-local action_timeout = 1;
+local action_timeout = 5;
 
 local property_rules = {};
 
@@ -59,6 +59,8 @@
 			end
 		elseif opt == "--skip-server-startup-log" then
 			skip_server_startup_log = true;
+		elseif opt == "--step-timeout" then
+			action_timeout = assert(tonumber(get_value()), "number expected for --step-timeout");
 		elseif opt == "--tag" then
 			local tag = get_value();
 			local key, value = tag:match("^([^=]+):(.+)$");
@@ -96,6 +98,9 @@
 		object.handler = o;
 		object.script = script;
 		apply_object_properties(object.type, object.name, object);
+		if object.type == "client" and not object.stanza_timeout then
+			object.stanza_timeout = action_timeout - 1;
+		end
 		o._validate(object);
 		c = c + 1;
 	end
--- a/scansion/objects/client.lua	Thu Feb 18 19:02:28 2016 +0000
+++ b/scansion/objects/client.lua	Fri Feb 19 11:47:33 2016 +0000
@@ -4,7 +4,7 @@
 
 local parse_xml = require "scansion.xml".parse;
 
-local stanza_timeout = 5;
+local default_stanza_timeout = 3;
 
 local stanzacmp = require "scansion.stanzacmp";
 
@@ -101,11 +101,15 @@
 			done();
 		end
 		client.stream:hook("stanza", stanza_handler, 100);
-		verse.add_task(stanza_timeout, function ()
-			if not expected_stanza then return; end -- Stanza already received
-			client.log("TIMEOUT waiting for %s", expected_stanza)
-			error("Timed out waiting for stanza");
-			done();
+		verse.add_task(client.stanza_timeout or default_stanza_timeout, function ()
+			if expected_stanza then
+				client.log("TIMEOUT waiting for %s", expected_stanza)
+				error("Timed out waiting for stanza");
+			end
+			if expected_stanza == false then
+				client.log("Good - no stanzas were received (expected)");
+				done();
+			end
 		end);
 		client.stream.conn:resume();
 		wait();

mercurial