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
40efd3a
commit 6cc11e5
Showing
6 changed files
with
181 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,70 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
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")) | ||
with pytest.raises(RuntimeError) as excinfo: | ||
await reader | ||
assert excinfo.value.args == ("connection closed",) | ||
|
||
|
||
async def test_closable_queue_close_get_nowait(loop): | ||
the_queue = asyncio.Queue() | ||
queue = ClosableQueue(the_queue) | ||
|
||
await the_queue.put(1) | ||
queue.close(RuntimeError("connection closed")) | ||
|
||
# even when the queue is closed, while there are items in the queu, we | ||
# allow reading them. | ||
assert queue.get_nowait() == 1 | ||
|
||
# when there are no more items in the queue, if there is a close exception | ||
# then it will get raises here | ||
with pytest.raises(RuntimeError) as excinfo: | ||
queue.get_nowait() | ||
assert excinfo.value.args == ("connection closed",) | ||
|
||
|
||
async def test_closable_queue_get_nowait_noclose(loop): | ||
the_queue = asyncio.Queue() | ||
queue = ClosableQueue(the_queue) | ||
await the_queue.put(1) | ||
assert queue.get_nowait() == 1 | ||
with pytest.raises(asyncio.QueueEmpty): | ||
queue.get_nowait() |