Mercurial > prosody-hg
comparison spec/util_async_spec.lua @ 8615:e77b37de482e
util.async: Behaviour change: continue to process queued items after errors
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 17 Mar 2018 14:54:48 +0000 |
| parents | bfbafeced0c4 |
| children | a15c891c6232 |
comparison
equal
deleted
inserted
replaced
| 8614:bfbafeced0c4 | 8615:e77b37de482e |
|---|---|
| 154 last_error = nil; | 154 last_error = nil; |
| 155 r:run("hello again"); | 155 r:run("hello again"); |
| 156 assert.equal(r.state, "ready"); | 156 assert.equal(r.state, "ready"); |
| 157 assert.equal(last_processed_item, "hello again"); | 157 assert.equal(last_processed_item, "hello again"); |
| 158 end); | 158 end); |
| 159 | |
| 160 it("should continue to process work items", function () | |
| 161 local wait, done, last_item; | |
| 162 local runner_func = spy.new(function (item) | |
| 163 if item == "error" then | |
| 164 error("test error"); | |
| 165 elseif item == "wait-error" then | |
| 166 wait, done = async.waiter(); | |
| 167 wait(); | |
| 168 error("test error"); | |
| 169 end | |
| 170 last_item = item; | |
| 171 end); | |
| 172 local runner = async.runner(runner_func, { error = spy.new(function () end) }); | |
| 173 runner:enqueue("one"); | |
| 174 runner:enqueue("error"); | |
| 175 runner:enqueue("two"); | |
| 176 runner:run(); | |
| 177 assert.equal(r.state, "ready"); | |
| 178 assert.equal(r.state, r.notified_state); | |
| 179 assert.spy(runner_func).was.called(3); | |
| 180 assert.spy(runner.watchers.error).was.called(1); | |
| 181 assert.equal(last_item, "two"); | |
| 182 end); | |
| 159 end); | 183 end); |
| 160 end); | 184 end); |
| 161 describe("#waiter", function() | 185 describe("#waiter", function() |
| 162 it("should error outside of async context", function () | 186 it("should error outside of async context", function () |
| 163 assert.has_error(function () | 187 assert.has_error(function () |
