Skip to content

Commit 46a015c

Browse files
authored
Merge pull request #1133 from ethho/dev-tests-plat-161-reconn
PLAT-161: Migrate test_reconnection
2 parents 88ca9b6 + e128632 commit 46a015c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test_reconnection.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Collection of test cases to test connection module.
3+
"""
4+
5+
import pytest
6+
import datajoint as dj
7+
from datajoint import DataJointError
8+
from . import CONN_INFO
9+
10+
11+
@pytest.fixture
12+
def conn(connection_root):
13+
return dj.conn(reset=True, **CONN_INFO)
14+
15+
16+
class TestReconnect:
17+
"""
18+
Test reconnection
19+
"""
20+
21+
def test_close(self, conn):
22+
assert conn.is_connected, "Connection should be alive"
23+
conn.close()
24+
assert not conn.is_connected, "Connection should now be closed"
25+
26+
def test_reconnect(self, conn):
27+
assert conn.is_connected, "Connection should be alive"
28+
conn.close()
29+
conn.query("SHOW DATABASES;", reconnect=True).fetchall()
30+
assert conn.is_connected, "Connection should be alive"
31+
32+
def test_reconnect_throws_error_in_transaction(self, conn):
33+
assert conn.is_connected, "Connection should be alive"
34+
with conn.transaction, pytest.raises(DataJointError):
35+
conn.close()
36+
conn.query("SHOW DATABASES;", reconnect=True).fetchall()

0 commit comments

Comments
 (0)