# HG changeset patch # User Matthew Wild # Date 1521311019 0 # Node ID 5325f0e1791b603c955d630e096964c19ce3d11e # Parent ab242c513bf46c7a9458757688a67232c3449bf2 util.async: tests: Ensure done() can be called before wait() diff -r ab242c513bf4 -r 5325f0e1791b spec/util_async_spec.lua --- a/spec/util_async_spec.lua Sat Mar 17 18:12:31 2018 +0000 +++ b/spec/util_async_spec.lua Sat Mar 17 18:23:39 2018 +0000 @@ -533,5 +533,23 @@ assert.equal(r1.state, "ready"); --for k, v in ipairs(l1) do print(k,v) end end); + + it("should allow done() to be called before wait()", function () + local processed_item; + local rf = spy.new(function (item) + local wait, done = async.waiter(); + done(); + wait(); + processed_item = item; + end); + local r = async.runner(rf, mock_watchers()); + r:run("test"); + assert.equal(processed_item, "test"); + assert.equal(r.state, "ready"); + -- Since the observable state did not change, + -- the watchers should not have been called + assert.spy(r.watchers.waiting).was_not.called(); + assert.spy(r.watchers.ready).was_not.called(); + end); end); end);