Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLAT-161: Migrate test_reconnection #1133

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/test_reconnection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Collection of test cases to test connection module.
"""

import pytest
import datajoint as dj
from datajoint import DataJointError
from . import CONN_INFO


@pytest.fixture
def conn(connection_root):
return dj.conn(reset=True, **CONN_INFO)


class TestReconnect:
"""
Test reconnection
"""

def test_close(self, conn):
assert conn.is_connected, "Connection should be alive"
conn.close()
assert not conn.is_connected, "Connection should now be closed"

def test_reconnect(self, conn):
assert conn.is_connected, "Connection should be alive"
conn.close()
conn.query("SHOW DATABASES;", reconnect=True).fetchall()
assert conn.is_connected, "Connection should be alive"

def test_reconnect_throws_error_in_transaction(self, conn):
assert conn.is_connected, "Connection should be alive"
with conn.transaction, pytest.raises(DataJointError):
conn.close()
conn.query("SHOW DATABASES;", reconnect=True).fetchall()