aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-03-16 22:26:15 +0000
committerMatthew Wild <mwild1@gmail.com>2018-03-16 22:26:15 +0000
commit5c0a12d4d1269e690a4b673cec9a95d0bb13dd9d (patch)
tree938421cd99e579bdd55b118790b6cd61d04afb92 /spec
parent2f1f98e1b5cd5dac6fb792ab34da7b767ffa8cd1 (diff)
downloadprosody-5c0a12d4d1269e690a4b673cec9a95d0bb13dd9d.tar.gz
prosody-5c0a12d4d1269e690a4b673cec9a95d0bb13dd9d.zip
util.async: Ensure runner is left in correct state after out-of-main-loop error (+tests)
Diffstat (limited to 'spec')
-rw-r--r--spec/util_async_spec.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/util_async_spec.lua b/spec/util_async_spec.lua
index 67438595..bc6e04f8 100644
--- a/spec/util_async_spec.lua
+++ b/spec/util_async_spec.lua
@@ -35,9 +35,14 @@ describe("util.async", function()
describe("#errors", function ()
local last_processed_item, last_error;
local r;
+ local wait, done;
r = async.runner(function (item)
if item == "error" then
error({ e = "test error" });
+ elseif item == "wait" then
+ wait, done = async.waiter();
+ wait();
+ error({ e = "post wait error" });
end
last_processed_item = item;
end, {
@@ -81,6 +86,24 @@ describe("util.async", function()
assert.equal(r.state, "ready");
assert.equal(last_processed_item, "world");
end);
+ it("should work despite a #waiter", function ()
+ -- This test covers an important case where a runner
+ -- throws an error while being executed outside of the
+ -- main loop. This happens when it was blocked ('waiting'),
+ -- and then released (via a call to done()).
+ last_error = nil;
+ r:run("wait");
+ assert.equal(r.state, "waiting");
+ done();
+ -- At this point an error happens (state goes error->ready)
+ assert.equal(r.state, "ready");
+ assert.is_table(last_error);
+ assert.equal(last_error.e, "post wait error");
+ last_error = nil;
+ r:run("hello again");
+ assert.equal(r.state, "ready");
+ assert.equal(last_processed_item, "hello again");
+ end);
end);
end);
describe("#waiter", function()