-
Notifications
You must be signed in to change notification settings - Fork 157
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 #249
- Loading branch information
1 parent
459cbe3
commit cdcc484
Showing
6 changed files
with
156 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,52 @@ | ||
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) | ||
queue.close(RuntimeError("connection closed")) | ||
with pytest.raises(RuntimeError) as excinfo: | ||
await queue.get_nowait() | ||
assert excinfo.value.args == ("connection closed",) |