mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Remove @asyncio.coroutine decorators
Signed-off-by: David Dashyan <mail@davie.li>
This commit is contained in:
parent
afe26f4cbf
commit
65baece9ba
@ -96,12 +96,11 @@ class Dispatcher:
|
|||||||
|
|
||||||
del self.subscribers[uuid]
|
del self.subscribers[uuid]
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def publish(self):
|
||||||
def publish(self):
|
|
||||||
"""Publish new events to the subscribers."""
|
"""Publish new events to the subscribers."""
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
event = yield from self.event_source.get()
|
event = await self.event_source.get()
|
||||||
str_buffer = []
|
str_buffer = []
|
||||||
|
|
||||||
if event == POISON_PILL:
|
if event == POISON_PILL:
|
||||||
@ -115,23 +114,22 @@ class Dispatcher:
|
|||||||
|
|
||||||
for str_item in str_buffer:
|
for str_item in str_buffer:
|
||||||
for _, websocket in self.subscribers.items():
|
for _, websocket in self.subscribers.items():
|
||||||
yield from websocket.send_str(str_item)
|
await websocket.send_str(str_item)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def websocket_handler(request):
|
||||||
def websocket_handler(request):
|
|
||||||
"""Handle a new socket connection."""
|
"""Handle a new socket connection."""
|
||||||
|
|
||||||
logger.debug('New websocket connection.')
|
logger.debug('New websocket connection.')
|
||||||
websocket = web.WebSocketResponse()
|
websocket = web.WebSocketResponse()
|
||||||
yield from websocket.prepare(request)
|
await websocket.prepare(request)
|
||||||
uuid = uuid4()
|
uuid = uuid4()
|
||||||
request.app['dispatcher'].subscribe(uuid, websocket)
|
request.app['dispatcher'].subscribe(uuid, websocket)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# Consume input buffer
|
# Consume input buffer
|
||||||
try:
|
try:
|
||||||
msg = yield from websocket.receive()
|
msg = await websocket.receive()
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
logger.debug('Websocket exception: %s', str(e))
|
logger.debug('Websocket exception: %s', str(e))
|
||||||
break
|
break
|
||||||
|
|||||||
@ -52,8 +52,7 @@ def test_eventify_block_works_with_any_transaction():
|
|||||||
assert event == expected
|
assert event == expected
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_bridge_sync_async_queue(loop):
|
||||||
def test_bridge_sync_async_queue(loop):
|
|
||||||
from bigchaindb.web.websocket_server import _multiprocessing_to_asyncio
|
from bigchaindb.web.websocket_server import _multiprocessing_to_asyncio
|
||||||
|
|
||||||
sync_queue = queue.Queue()
|
sync_queue = queue.Queue()
|
||||||
@ -69,16 +68,16 @@ def test_bridge_sync_async_queue(loop):
|
|||||||
sync_queue.put('der')
|
sync_queue.put('der')
|
||||||
sync_queue.put('Autobahn')
|
sync_queue.put('Autobahn')
|
||||||
|
|
||||||
result = yield from async_queue.get()
|
result = await async_queue.get()
|
||||||
assert result == 'fahren'
|
assert result == 'fahren'
|
||||||
|
|
||||||
result = yield from async_queue.get()
|
result = await async_queue.get()
|
||||||
assert result == 'auf'
|
assert result == 'auf'
|
||||||
|
|
||||||
result = yield from async_queue.get()
|
result = await async_queue.get()
|
||||||
assert result == 'der'
|
assert result == 'der'
|
||||||
|
|
||||||
result = yield from async_queue.get()
|
result = await async_queue.get()
|
||||||
assert result == 'Autobahn'
|
assert result == 'Autobahn'
|
||||||
|
|
||||||
assert async_queue.qsize() == 0
|
assert async_queue.qsize() == 0
|
||||||
@ -110,33 +109,31 @@ def test_start_creates_an_event_loop(queue_mock, get_event_loop_mock,
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_websocket_string_event(test_client, loop):
|
||||||
def test_websocket_string_event(test_client, loop):
|
|
||||||
from bigchaindb.web.websocket_server import init_app, POISON_PILL, EVENTS_ENDPOINT
|
from bigchaindb.web.websocket_server import init_app, POISON_PILL, EVENTS_ENDPOINT
|
||||||
|
|
||||||
event_source = asyncio.Queue(loop=loop)
|
event_source = asyncio.Queue(loop=loop)
|
||||||
app = init_app(event_source, loop=loop)
|
app = init_app(event_source, loop=loop)
|
||||||
client = yield from test_client(app)
|
client = await test_client(app)
|
||||||
ws = yield from client.ws_connect(EVENTS_ENDPOINT)
|
ws = await client.ws_connect(EVENTS_ENDPOINT)
|
||||||
|
|
||||||
yield from event_source.put('hack')
|
await event_source.put('hack')
|
||||||
yield from event_source.put('the')
|
await event_source.put('the')
|
||||||
yield from event_source.put('planet!')
|
await event_source.put('planet!')
|
||||||
|
|
||||||
result = yield from ws.receive()
|
result = await ws.receive()
|
||||||
assert result.data == 'hack'
|
assert result.data == 'hack'
|
||||||
|
|
||||||
result = yield from ws.receive()
|
result = await ws.receive()
|
||||||
assert result.data == 'the'
|
assert result.data == 'the'
|
||||||
|
|
||||||
result = yield from ws.receive()
|
result = await ws.receive()
|
||||||
assert result.data == 'planet!'
|
assert result.data == 'planet!'
|
||||||
|
|
||||||
yield from event_source.put(POISON_PILL)
|
await event_source.put(POISON_PILL)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_websocket_block_event(b, test_client, loop):
|
||||||
def test_websocket_block_event(b, test_client, loop):
|
|
||||||
from bigchaindb import events
|
from bigchaindb import events
|
||||||
from bigchaindb.web.websocket_server import init_app, POISON_PILL, EVENTS_ENDPOINT
|
from bigchaindb.web.websocket_server import init_app, POISON_PILL, EVENTS_ENDPOINT
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
@ -148,22 +145,22 @@ def test_websocket_block_event(b, test_client, loop):
|
|||||||
|
|
||||||
event_source = asyncio.Queue(loop=loop)
|
event_source = asyncio.Queue(loop=loop)
|
||||||
app = init_app(event_source, loop=loop)
|
app = init_app(event_source, loop=loop)
|
||||||
client = yield from test_client(app)
|
client = await test_client(app)
|
||||||
ws = yield from client.ws_connect(EVENTS_ENDPOINT)
|
ws = await client.ws_connect(EVENTS_ENDPOINT)
|
||||||
block = {'height': 1, 'transactions': [tx]}
|
block = {'height': 1, 'transactions': [tx]}
|
||||||
block_event = events.Event(events.EventTypes.BLOCK_VALID, block)
|
block_event = events.Event(events.EventTypes.BLOCK_VALID, block)
|
||||||
|
|
||||||
yield from event_source.put(block_event)
|
await event_source.put(block_event)
|
||||||
|
|
||||||
for tx in block['transactions']:
|
for tx in block['transactions']:
|
||||||
result = yield from ws.receive()
|
result = await ws.receive()
|
||||||
json_result = json.loads(result.data)
|
json_result = json.loads(result.data)
|
||||||
assert json_result['transaction_id'] == tx.id
|
assert json_result['transaction_id'] == tx.id
|
||||||
# Since the transactions are all CREATEs, asset id == transaction id
|
# Since the transactions are all CREATEs, asset id == transaction id
|
||||||
assert json_result['asset_id'] == tx.id
|
assert json_result['asset_id'] == tx.id
|
||||||
assert json_result['height'] == block['height']
|
assert json_result['height'] == block['height']
|
||||||
|
|
||||||
yield from event_source.put(POISON_PILL)
|
await event_source.put(POISON_PILL)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip('Processes are not stopping properly, and the whole test suite would hang')
|
@pytest.mark.skip('Processes are not stopping properly, and the whole test suite would hang')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user