Skip to content

Commit

Permalink
fix premature exit of AsyncDictionary test
Browse files Browse the repository at this point in the history
  • Loading branch information
belm0 committed Sep 17, 2020
1 parent 95218a2 commit 44ea836
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions tests/test_async_dictionary.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import trio
from trio_util import AsyncDictionary
from trio_util import AsyncDictionary, wait_all

async def test_async_dictionary(nursery, autojump_clock):
async def reader(d):

async def test_async_dictionary(autojump_clock):
d = AsyncDictionary(foo=10)
assert len(d) == 1
assert 'foo' in d
assert list(d) == ['foo']
assert await d.get_wait('foo') == 10
assert not d.is_waiting('foo')
del d['foo']
assert not d

async def reader():
assert await d.get_wait('bar') == 99
assert 'bar' in d
assert await d.pop_wait('baz') == 'done'
Expand All @@ -11,21 +21,12 @@ async def reader(d):
await d.get_wait('baz')
assert False

async def writer(d):
async def writer():
await trio.sleep(.1)
assert d.is_waiting('bar')
d['bar'] = 99
await trio.sleep(.1)
assert d.is_waiting('baz')
d['baz'] = 'done'

d = AsyncDictionary(foo=10)
assert len(d) == 1
assert 'foo' in d
assert list(d) == ['foo']
assert await d.get_wait('foo') == 10
assert not d.is_waiting('foo')
del d['foo']
assert not d
nursery.start_soon(reader, d)
nursery.start_soon(writer, d)
await wait_all(reader, writer)

0 comments on commit 44ea836

Please sign in to comment.