Merge pull request #750 from meejah/issue747-future-loops

Issue747 future loops
This commit is contained in:
Tobias Oberstein 2016-11-04 17:46:40 +01:00 committed by GitHub
commit b1a4c080a5
4 changed files with 41 additions and 4 deletions

View File

@ -69,14 +69,14 @@ class PrefixProtocol(asyncio.Protocol):
self.log.debug('RawSocker Asyncio: Connection made with peer {peer}', peer=self.peer)
self._buffer = b''
self._header = None
self._wait_closed = asyncio.Future()
self._wait_closed = txaio.create_future()
@property
def is_closed(self):
if hasattr(self, '_wait_closed'):
return self._wait_closed
else:
f = asyncio.Future()
f = txaio.create_future()
f.set_result(True)
return f

View File

@ -0,0 +1,34 @@
import pytest
import os
# because py.test tries to collect it as a test-case
try:
from asyncio.test_utils import TestLoop as AsyncioTestLoop
except ImportError:
from trollius.test_utils import TestLoop as AsyncioTestLoop
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from autobahn.asyncio.websocket import WebSocketServerFactory
from unittest import TestCase
@pytest.mark.usefixtures("event_loop") # ensure we have pytest_asyncio installed
@pytest.mark.skipif(os.environ.get('USE_ASYNCIO', False), reason="Only for asyncio")
class Test(TestCase):
@pytest.mark.asyncio(forbid_global_loop=True)
def test_websocket_custom_loop(self):
def time_gen():
yield
yield
loop = AsyncioTestLoop(time_gen)
factory = WebSocketServerFactory(loop=loop)
server = factory()
transport = Mock()
server.connection_made(transport)

View File

@ -104,7 +104,7 @@ class WebSocketAdapterProtocol(asyncio.Protocol):
self.transport = None
def _consume(self):
self.waiter = Future()
self.waiter = Future(loop=self.factory.loop or txaio.config.loop)
def process(_):
while len(self.receive_queue):
@ -243,6 +243,8 @@ class WebSocketServerFactory(WebSocketAdapterFactory, protocol.WebSocketServerFa
Base class for asyncio-based WebSocket server factories.
"""
protocol = WebSocketServerProtocol
def __init__(self, *args, **kwargs):
"""
In addition to all arguments to the constructor of

View File

@ -130,12 +130,13 @@ extras_require_dev = [
'pyenchant>=1.6.6', # LGPL
'sphinxcontrib-spelling>=2.1.2', # BSD
'sphinx_rtd_theme>=0.1.9', # BSD
'pytest_asyncio',
]
# for testing by users with "python setup.py test" (not Tox, which we use)
test_requirements = [
"pytest>=2.8.6", # MIT license
"mock>=1.3.0" # BSD license
"mock>=1.3.0", # BSD license
]