Skip to content

Commit fa27dac

Browse files
committed
Fix trio driver and add regression test
1 parent aa7f070 commit fa27dac

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ mock==2.0.0
33
pytest-cov==2.6.1
44
pytest==4.3.1
55
six==1.12.0
6+
trio==0.11.0
7+
pytest-trio==0.5.2

rethinkdb/trio_net/net_trio.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from rethinkdb.errors import ReqlAuthError, ReqlCursorEmpty, ReqlDriverError, \
2929
ReqlTimeoutError, RqlCursorEmpty
3030
from rethinkdb.net import Connection as ConnectionBase, Cursor, Query, \
31-
Response, maybe_profile, connect
31+
Response, maybe_profile, make_connection
3232

3333

3434
__all__ = ['Connection']
@@ -415,7 +415,8 @@ def open(cls, *args, **kwargs):
415415
return cls(*args, **kwargs)
416416

417417
async def __aenter__(self):
418-
self._conn = await connect(*self._args, **self._kwargs)
418+
self._conn = await make_connection(Connection, *self._args,
419+
**self._kwargs)
419420
return self._conn
420421

421422
async def __aexit__(self, exc_type, exc, traceback):
@@ -480,7 +481,7 @@ async def acquire(self):
480481
# still connected.
481482
conn = self._connections.popleft()
482483
except IndexError:
483-
conn = await connect(*self._args, **self._kwargs)
484+
conn = await make_connection(*self._args, **self._kwargs)
484485

485486
self._lent_out.add(conn)
486487
return conn

tests/integration/test_trio.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import sys
3+
from collections import namedtuple
4+
import pytest
5+
from rethinkdb import RethinkDB
6+
from rethinkdb.errors import ReqlRuntimeError
7+
import trio
8+
9+
INTEGRATION_TEST_DB = 'integration_test'
10+
r = RethinkDB()
11+
r.set_loop_type('trio')
12+
13+
14+
@pytest.fixture
15+
async def integration_db(nursery):
16+
async with r.open(db='test', nursery=nursery) as conn:
17+
try:
18+
await r.db_create(INTEGRATION_TEST_DB).run(conn)
19+
except ReqlRuntimeError:
20+
pass
21+
yield r.db(INTEGRATION_TEST_DB)
22+
23+
24+
@pytest.fixture
25+
async def marvel_table(integration_db, nursery):
26+
async with r.open(db='test', nursery=nursery) as conn:
27+
await r.table_create('marvel').run(conn)
28+
yield r.table('marvel')
29+
await r.table_drop('marvel').run(conn)
30+
31+
32+
@pytest.mark.trio
33+
@pytest.mark.integration
34+
@pytest.mark.skipif(sys.version_info < (3, 6),
35+
reason="Async generators require python ≥ 3.6")
36+
async def test_trio(marvel_table, nursery):
37+
"""
38+
Test the flow for 3.6 and up, async generators are
39+
not supported in 3.5.
40+
"""
41+
async with r.open(db='test', nursery=nursery) as conn:
42+
await marvel_table.insert({
43+
'id': 1,
44+
'name': 'Iron Man',
45+
'first_appearance': 'Tales of Suspense #39'
46+
}).run(conn)
47+
48+
cursor = await marvel_table.run(conn)
49+
async for hero in cursor:
50+
hero['name'] == 'Iron Man'

0 commit comments

Comments
 (0)