Skip to content

Commit

Permalink
[fix] pool tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mosquito committed Nov 20, 2019
1 parent afb5a08 commit 6168cd3
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions tests/test_pool.py
Expand Up @@ -78,22 +78,25 @@ def setUp(self):
super().setUp()

async def create_instance(self):
obj = TestCaseClose.Instanse()
obj = TestCaseClose.Instance()
self.instances.add(obj)
return obj

async def test_close(self):
async def getter():
async with self.pool.acquire() as instance:
assert instance > 0
await asyncio.sleep(0.01)
return self.counter
async with self.pool.acquire():
await asyncio.sleep(0.05)

self.assertFalse(self.pool.is_closed)
self.assertTrue(len(self.instances) == 0)

await asyncio.gather(
*[getter() for _ in range(200)],
loop=self.loop, return_exceptions=True
)

self.assertTrue(len(self.instances) > 1)

for instance in self.instances:
self.assertFalse(instance.closed)

Expand All @@ -102,27 +105,35 @@ async def getter():
for instance in self.instances:
self.assertTrue(instance.closed)

self.assertTrue(self.pool.is_closed)

async def test_close_context_manager(self):
async def getter():
async with self.pool.acquire() as instance:
assert instance > 0
await asyncio.sleep(0.01)
return self.counter
async with self.pool.acquire():
await asyncio.sleep(0.05)

async with self.pool:
self.assertFalse(self.pool.is_closed)

self.assertTrue(len(self.instances) == 0)

await asyncio.gather(
*[getter() for _ in range(200)],
loop=self.loop, return_exceptions=True
)

self.assertTrue(len(self.instances) > 1)

for instance in self.instances:
self.assertFalse(instance.closed)

for instance in self.instances:
self.assertTrue(instance.closed)
self.assertFalse(self.pool.is_closed)

self.assertTrue(self.pool.is_closed)

for instance in self.instances:
self.assertTrue(instance.closed)


class TestCaseNoMaxSize(BaseTestCase):
max_size = None
Expand Down

0 comments on commit 6168cd3

Please sign in to comment.