Skip to content

Commit

Permalink
Add basic gc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti committed Jun 21, 2024
1 parent 8803d0c commit 1f4431a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/integration/gc_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import gc
import pytest
import weakref
import pyexasol


@pytest.mark.misc
def test_exa_statement_gets_garbage_collected(connection):
# Execute statement, read some data
stmt = connection.execute("SELECT * FROM users")
stmt_ref = weakref.ref(stmt)
stmt.fetchmany(5)

assert stmt_ref() is not None

# Execute another statement, no more references for the first statement
stmt = connection.execute("SELECT * FROM payments")
stmt.fetchmany(5)

# collect unreferenced objects
gc.collect()

assert stmt_ref() is None


@pytest.mark.misc
def test_exa_connection_gets_garbage_collected(dsn, user, password, schema):
# create connection
con = pyexasol.connect(
dsn=dsn, user=user, password=password, schema=schema
)
stmt_ref = weakref.ref(con)

assert stmt_ref() is not None

# replace binding to old connection object
con = pyexasol.connect(
dsn=dsn, user=user, password=password, schema=schema
)

# collect unreferenced objects
gc.collect()

assert stmt_ref() is None

0 comments on commit 1f4431a

Please sign in to comment.