aboutsummaryrefslogtreecommitdiffstats
path: root/spec
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
commit364f1605a88bb07b52af85a6e02c75e1c5e02db2 (patch)
tree7d9dea8636b8ad20a02c1cb6ff80e39ff1ac3d88 /spec
parent945ae93e319c8367882bbd0c9e80ff3721d34524 (diff)
downloadprosody-364f1605a88bb07b52af85a6e02c75e1c5e02db2.tar.gz
prosody-364f1605a88bb07b52af85a6e02c75e1c5e02db2.zip
util.async: Add tests to specifically cover error handling
Diffstat (limited to 'spec')
-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 ()