diff options
| author | William Boman <william@redwill.se> | 2023-08-17 19:34:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-17 19:34:23 +0200 |
| commit | b5bb138312dbd3f7729197ca659cbe5221d36a03 (patch) | |
| tree | a0d5a79d6e743693e4f064e5a091ed4f0e47ac89 /tests/mason-core | |
| parent | fix(ui): properly reset new package version state (#1454) (diff) | |
| download | mason-b5bb138312dbd3f7729197ca659cbe5221d36a03.tar mason-b5bb138312dbd3f7729197ca659cbe5221d36a03.tar.gz mason-b5bb138312dbd3f7729197ca659cbe5221d36a03.tar.bz2 mason-b5bb138312dbd3f7729197ca659cbe5221d36a03.tar.lz mason-b5bb138312dbd3f7729197ca659cbe5221d36a03.tar.xz mason-b5bb138312dbd3f7729197ca659cbe5221d36a03.tar.zst mason-b5bb138312dbd3f7729197ca659cbe5221d36a03.zip | |
chore(async): add Channel (#1456)
Diffstat (limited to 'tests/mason-core')
| -rw-r--r-- | tests/mason-core/async/async_spec.lua | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/mason-core/async/async_spec.lua b/tests/mason-core/async/async_spec.lua index 29ffd946..61eeeb1b 100644 --- a/tests/mason-core/async/async_spec.lua +++ b/tests/mason-core/async/async_spec.lua @@ -311,3 +311,58 @@ describe("async :: OneShotChannel", function() assert.equals(42, channel:receive()) end) end) + +describe("async :: Channel", function() + local Channel = control.Channel + + it("should suspend send until buffer is received", function() + local channel = Channel.new() + spy.on(channel, "send") + local guard = spy.new() + + a.run(function() + channel:send "message" + guard() + channel:send "another message" + end, function() end) + + assert.spy(channel.send).was_called(1) + assert.spy(channel.send).was_called_with(match.is_ref(channel), "message") + assert.spy(guard).was_not_called() + end) + + it("should send subsequent messages after they're received", function() + local channel = Channel.new() + spy.on(channel, "send") + + a.run(function() + channel:send "message" + channel:send "another message" + end, function() end) + + local value = channel:receive() + assert.equals(value, "message") + + assert.spy(channel.send).was_called(2) + assert.spy(channel.send).was_called_with(match.is_ref(channel), "message") + assert.spy(channel.send).was_called_with(match.is_ref(channel), "another message") + end) + + it("should suspend receive until message is sent", function() + local channel = Channel.new() + + a.run(function() + a.sleep(100) + channel:send "hello world" + end, function() end) + + local start = timestamp() + local value = a.run_blocking(function() + return channel:receive() + end) + local stop = timestamp() + + assert.is_true((stop - start) > 80) + assert.equals(value, "hello world") + end) +end) |
