forked from aio-libs/aiopg
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix "Unable to detect disconnect when using NOTIFY/LISTEN", Closes ai…
- Loading branch information
1 parent
459cbe3
commit 95f6203
Showing
6 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import asyncio | ||
|
||
from aiopg.utils import ClosableQueue | ||
|
||
|
||
async def test_closable_queue_noclose(): | ||
the_queue = asyncio.Queue() | ||
queue = ClosableQueue(the_queue) | ||
assert queue.empty() | ||
assert queue.qsize() == 0 | ||
|
||
await the_queue.put(1) | ||
assert not queue.empty() | ||
assert queue.qsize() == 1 | ||
v = await queue.get() | ||
assert v == 1 | ||
|
||
await the_queue.put(2) | ||
v = queue.get_nowait() | ||
assert v == 2 | ||
|
||
|
||
async def test_closable_queue_close(loop): | ||
the_queue = asyncio.Queue() | ||
queue = ClosableQueue(the_queue) | ||
v1 = None | ||
|
||
async def read(): | ||
nonlocal v1 | ||
v1 = await queue.get() | ||
await queue.get() | ||
|
||
reader = loop.create_task(read()) | ||
await the_queue.put(1) | ||
await asyncio.sleep(0.1) | ||
assert v1 == 1 | ||
|
||
queue.close(RuntimeError("connection closed")) | ||
try: | ||
await reader | ||
except RuntimeError as ex: | ||
assert ex.args == ("connection closed",) |