aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_async_spec.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-03-16 17:50:16 +0000
committerMatthew Wild <mwild1@gmail.com>2018-03-16 17:50:16 +0000
commitb0211d2247a32a4fb963bb1e6d4d6c6fec6cbf52 (patch)
tree7d9dea8636b8ad20a02c1cb6ff80e39ff1ac3d88 /spec/util_async_spec.lua
parent9a63fdd773d2d37602d377d9d279c42cb6280fc5 (diff)
downloadprosody-b0211d2247a32a4fb963bb1e6d4d6c6fec6cbf52.tar.gz
prosody-b0211d2247a32a4fb963bb1e6d4d6c6fec6cbf52.zip
util.async: Add tests to specifically cover error handling
Diffstat (limited to 'spec/util_async_spec.lua')
-rw-r--r--spec/util_async_spec.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/util_async_spec.lua b/spec/util_async_spec.lua
index 9681673f..24f2efdb 100644
--- a/spec/util_async_spec.lua
+++ b/spec/util_async_spec.lua
@@ -26,6 +26,62 @@ describe("util.async", function()
r:run(1);
r:run(2);
end);
+
+ it("should be ready after creation", function ()
+ local r = async.runner(function (item) end);
+ assert.equal(r.state, "ready");
+ end);
+
+ describe("#errors", function ()
+ local last_processed_item, last_error;
+ local r;
+ r = async.runner(function (item)
+ if item == "error" then
+ error({ e = "test error" });
+ end
+ last_processed_item = item;
+ end, {
+ error = function (runner, err)
+ assert.equal(r, runner);
+ last_error = err;
+ end;
+ });
+
+ randomize(false);
+
+ it("should notify", function ()
+ local last_processed_item, last_error;
+ local r;
+ r = async.runner(function (item)
+ if item == "error" then
+ error({ e = "test error" });
+ end
+ last_processed_item = item;
+ end, {
+ error = function (runner, err)
+ assert.equal(r, runner);
+ last_error = err;
+ end;
+ });
+
+ r:run("hello");
+ assert.equal(r.state, "ready");
+ assert.equal(last_processed_item, "hello");
+
+ assert.equal(last_error, nil);
+ r:run("error");
+ assert.is_table(last_error);
+ assert.equal(last_error.e, "test error");
+ last_error = nil;
+ assert.equal(r.state, "ready");
+ assert.equal(last_processed_item, "hello");
+ end);
+ it("should not be fatal to the runner", function ()
+ r:run("world");
+ assert.equal(r.state, "ready");
+ assert.equal(last_processed_item, "world");
+ end);
+ end);
end);
describe("#waiter", function()
it("should work", function ()