8000 Use asyncio.ensure_future in tests (instead of asyncio.async). · chdsbd/asyncio-redis@019c176 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 019c176

Browse files
Use asyncio.ensure_future in tests (instead of asyncio.async).
1 parent 82bd302 commit 019c176

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

tests.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
START_REDIS_SERVER = bool(os.environ.get('START_REDIS_SERVER', False))
5555

5656

57+
# In Python 3.4.4, `async` was renamed to `ensure_future`.
58+
try:
59+
ensure_future = asyncio.ensure_future
60+
except AttributeError:
61+
ensure_future = asyncio.async
62+
63+
5764
@asyncio.coroutine
5865
def connect(loop, protocol=RedisProtocol):
5966
""" Connect to redis server. Return transport/protocol pair. """
@@ -564,7 +571,7 @@ def blpop():
564571
self.assertEqual(value.list_name, u'my_list')
565572
self.assertEqual(value.value, u'value')
566573
test_order.append('#3')
567-
f = asyncio.async(blpop(), loop=self.loop)
574+
f = ensure_future(blpop(), loop=self.loop)
568575

569576
transport2, protocol2 = yield from connect(self.loop)
570577

@@ -580,7 +587,7 @@ def blpop():
580587
self.assertIsInstance(value, BlockingPopReply)
581588
self.assertEqual(value.list_name, u'my_list')
582589
self.assertEqual(value.value, u'value2')
583-
f = asyncio.async(blpop(), loop=self.loop)
590+
f = ensure_future(blpop(), loop=self.loop)
584591

585592
yield from protocol2.rpush(u'my_list', [u'value2'])
586593
yield from f
@@ -597,7 +604,7 @@ def test_brpoplpush(self, transport, protocol):
597604
def brpoplpush():
598605
result = yield from protocol.brpoplpush(u'from', u'to')
599606
self.assertEqual(result, u'my_value')
600-
f = asyncio.async(brpoplpush(), loop=self.loop)
607+
f = ensure_future(brpoplpush(), loop=self.loop)
601608

602609
transport2, protocol2 = yield from connect(self.loop)
603610
yield from protocol2.rpush(u'from', [u'my_value'])
@@ -838,7 +845,7 @@ def listener():
838845

839846
return transport2
840847

841-
f = asyncio.async(listener(), loop=self.loop)
848+
f = ensure_future(listener(), loop=self.loop)
842849

843850
@asyncio.coroutine
844851
def sender():
@@ -906,7 +913,7 @@ def listener():
906913

907914
transport2.close()
908915

909-
f = asyncio.async(listener(), loop=self.loop)
916+
f = ensure_future(listener(), loop=self.loop)
910917

911918
@asyncio.coroutine
912919
def sender():
@@ -948,7 +955,7 @@ def listener():
948955

949956
transport2.close()
950957

951-
f = asyncio.async(listener(), loop=self.loop)
958+
f = ensure_future(listener(), loop=self.loop)
952959

953960
@asyncio.coroutine
954961
def sender():
@@ -1441,7 +1448,7 @@ def run_while_true():
14411448
transport.close()
14421449

14431450
# (start script)
1444-
f = asyncio.async(run_while_true(), loop=self.loop)
1451+
f = ensure_future(run_while_true(), loop=self.loop)
14451452
yield from asyncio.sleep(.5, loop=self.loop)
14461453

14471454
result = yield from protocol.script_kill()
@@ -1773,7 +1780,7 @@ def test_cancellation(self, transport, protocol):
17731780
@asyncio.coroutine
17741781
def run():
17751782
yield from protocol.brpop(['key'], 3)
1776-
f = asyncio.async(run(), loop=self.loop)
1783+
f = ensure_future(run(), loop=self.loop)
17771784

17781785
# We cancel the coroutine before the answer arrives.
17791786
yield from asyncio.sleep(.5, loop=self.loop)
@@ -1900,7 +1907,7 @@ def listener():
19001907
def sender():
19011908
value = yield from protocol.publish(b'our_channel', b'message1')
19021909

1903-
f = asyncio.async(listener(), loop=self.loop)
1910+
f = ensure_future(listener(), loop=self.loop)
19041911
yield from asyncio.sleep(.5, loop=self.loop)
19051912
yield from sender()
19061913
transport2 = yield from f
@@ -1992,7 +1999,7 @@ def test():
19921999

19932000
# Wait for ever. (This blocking pop doesn't return.)
19942001
yield from connection.delete([ 'unknown-key' ])
1995-
f = asyncio.async(connection.blpop(['unknown-key']), loop=self.loop)
2002+
f = ensure_future(connection.blpop(['unknown-key']), loop=self.loop)
19962003
yield from asyncio.sleep(.1, loop=self.loop) # Sleep to make sure that the above coroutine started executing.
19972004

19982005
# Run command in other thread.
@@ -2040,8 +2047,8 @@ def source():
20402047
yield from asyncio.sleep(.5, loop=self.loop)
20412048

20422049
# Run both coroutines.
2043-
f1 = asyncio.async(source(), loop=self.loop)
2044-
f2 = asyncio.async(sink(), loop=self.loop)
2050+
f1 = ensure_future(source(), loop=self.loop)
2051+
f2 = ensure_future(sink(), loop=self.loop)
20452052
yield from gather(f1, f2)
20462053

20472054
# Test results.
@@ -2095,7 +2102,7 @@ def sink(i):
20952102
futures = []
20962103
for i in range(0, 10):
20972104
self.assertEqual(connection.connections_in_use, i)
2098-
futures.append(asyncio.async(sink(i), loop=self.loop))
2105+
futures.append(ensure_future(sink(i), loop=self.loop))
20992106
yield from asyncio.sleep(.1, loop=self.loop) # Sleep to make sure that the above coroutine started executing.
21002107

21012108
# One more blocking call should fail.

0 commit comments

Comments
 (0)
0