Software /
code /
prosody
Comparison
spec/util_async_spec.lua @ 8628:e88744fa0985
util.async: Add some more tests for wait/done
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 18 Mar 2018 22:43:06 +0000 |
parent | 8624:5325f0e1791b |
child | 8630:deade38ffbbd |
comparison
equal
deleted
inserted
replaced
8627:24b59a62acce | 8628:e88744fa0985 |
---|---|
532 | 532 |
533 assert.equal(r1.state, "ready"); | 533 assert.equal(r1.state, "ready"); |
534 --for k, v in ipairs(l1) do print(k,v) end | 534 --for k, v in ipairs(l1) do print(k,v) end |
535 end); | 535 end); |
536 | 536 |
537 it("should support multiple done() calls", function () | |
538 local processed_item; | |
539 local wait, done; | |
540 local rf = spy.new(function (item) | |
541 wait, done = async.waiter(4); | |
542 wait(); | |
543 processed_item = item; | |
544 end); | |
545 local r = async.runner(rf, mock_watchers()); | |
546 r:run("test"); | |
547 for i = 1, 3 do | |
548 done(); | |
549 assert.equal(r.state, "waiting"); | |
550 assert.is_nil(processed_item); | |
551 end | |
552 done(); | |
553 assert.equal(r.state, "ready"); | |
554 assert.equal(processed_item, "test"); | |
555 assert.spy(r.watchers.error).was_not.called(); | |
556 end); | |
557 | |
558 it("should not allow done() to be called more than specified", function () | |
559 local processed_item; | |
560 local wait, done; | |
561 local rf = spy.new(function (item) | |
562 wait, done = async.waiter(4); | |
563 wait(); | |
564 processed_item = item; | |
565 end); | |
566 local r = async.runner(rf, mock_watchers()); | |
567 r:run("test"); | |
568 for i = 1, 4 do | |
569 done(); | |
570 end | |
571 assert.has_error(done);; | |
572 assert.equal(r.state, "ready"); | |
573 assert.equal(processed_item, "test"); | |
574 assert.spy(r.watchers.error).was_not.called(); | |
575 end); | |
576 | |
537 it("should allow done() to be called before wait()", function () | 577 it("should allow done() to be called before wait()", function () |
538 local processed_item; | 578 local processed_item; |
539 local rf = spy.new(function (item) | 579 local rf = spy.new(function (item) |
540 local wait, done = async.waiter(); | 580 local wait, done = async.waiter(); |
541 done(); | 581 done(); |