-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |