From 44ea8367f9c47885a3a53a17cf678a6fefd88775 Mon Sep 17 00:00:00 2001 From: John Belmonte Date: Thu, 17 Sep 2020 22:45:56 +0900 Subject: [PATCH] fix premature exit of AsyncDictionary test --- tests/test_async_dictionary.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tests/test_async_dictionary.py b/tests/test_async_dictionary.py index 2a20a5b..386399e 100644 --- a/tests/test_async_dictionary.py +++ b/tests/test_async_dictionary.py @@ -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' @@ -11,7 +21,7 @@ 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 @@ -19,13 +29,4 @@ async def writer(d): 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)