aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_async_spec.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-03-18 22:43:06 +0000
committerMatthew Wild <mwild1@gmail.com>2018-03-18 22:43:06 +0000
commitb539a1019ffa8e8a7212a47393dd69a63d397887 (patch)
treebd52f57518a5ba5d345d9dbbcde82f6cb1bf0905 /spec/util_async_spec.lua
parent64594ce6f386b6b6b21d6bbe2c56bd003e15d508 (diff)
downloadprosody-b539a1019ffa8e8a7212a47393dd69a63d397887.tar.gz
prosody-b539a1019ffa8e8a7212a47393dd69a63d397887.zip
util.async: Add some more tests for wait/done
Diffstat (limited to 'spec/util_async_spec.lua')
-rw-r--r--spec/util_async_spec.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/util_async_spec.lua b/spec/util_async_spec.lua
index 5b27c17b..68c137e5 100644
--- a/spec/util_async_spec.lua
+++ b/spec/util_async_spec.lua
@@ -534,6 +534,46 @@ describe("util.async", function()
--for k, v in ipairs(l1) do print(k,v) end
end);
+ it("should support multiple done() calls", function ()
+ local processed_item;
+ local wait, done;
+ local rf = spy.new(function (item)
+ wait, done = async.waiter(4);
+ wait();
+ processed_item = item;
+ end);
+ local r = async.runner(rf, mock_watchers());
+ r:run("test");
+ for i = 1, 3 do
+ done();
+ assert.equal(r.state, "waiting");
+ assert.is_nil(processed_item);
+ end
+ done();
+ assert.equal(r.state, "ready");
+ assert.equal(processed_item, "test");
+ assert.spy(r.watchers.error).was_not.called();
+ end);
+
+ it("should not allow done() to be called more than specified", function ()
+ local processed_item;
+ local wait, done;
+ local rf = spy.new(function (item)
+ wait, done = async.waiter(4);
+ wait();
+ processed_item = item;
+ end);
+ local r = async.runner(rf, mock_watchers());
+ r:run("test");
+ for i = 1, 4 do
+ done();
+ end
+ assert.has_error(done);;
+ assert.equal(r.state, "ready");
+ assert.equal(processed_item, "test");
+ assert.spy(r.watchers.error).was_not.called();
+ end);
+
it("should allow done() to be called before wait()", function ()
local processed_item;
local rf = spy.new(function (item)