Software /
code /
prosody
Changeset
8607:62bb06cf8a43
util.async: Add tests to specifically cover error handling
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 16 Mar 2018 17:50:16 +0000 |
parents | 8606:b6b1f0f9b381 |
children | 8608:a2e6caf5848d |
files | spec/util_async_spec.lua |
diffstat | 1 files changed, 56 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/spec/util_async_spec.lua Fri Mar 16 17:36:49 2018 +0000 +++ b/spec/util_async_spec.lua Fri Mar 16 17:50:16 2018 +0000 @@ -26,6 +26,62 @@ 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 ()