Skip to content

Commit

Permalink
test(gc): add test to ensure that the tables accessor does not create…
Browse files Browse the repository at this point in the history
… a strong reference
  • Loading branch information
cpcloud authored and ncclementi committed Aug 26, 2024
1 parent a402095 commit f97d704
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ibis/backends/duckdb/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import gc
import os
import subprocess
import sys
Expand Down Expand Up @@ -403,3 +404,23 @@ def test_read_csv_with_types(tmp_path, input, all_varchar):
path.write_bytes(data)
t = con.read_csv(path, all_varchar=all_varchar, **input)
assert t.schema()["geom"].is_geospatial()


def test_tables_accessor_no_reference_cycle():
"""Test that a single reference to a connection has the desired lifetime semantics."""
con = ibis.duckdb.connect()

before = len(gc.get_referrers(con))
tables = con.tables
after = len(gc.get_referrers(con))

assert after == before

# valid call, and there are no tables in the database
assert not list(tables)

del con

# no longer valid because the backend has been manually decref'd
with pytest.raises(ReferenceError):
list(tables)
12 changes: 12 additions & 0 deletions ibis/backends/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import gc

import pytest
from pytest import param

Expand Down Expand Up @@ -115,6 +117,16 @@ def test_tables_accessor_repr(con):
assert f"- {name}" in result


def test_tables_accessor_no_reference_cycle(con):
before = len(gc.get_referrers(con))
_ = con.tables
after = len(gc.get_referrers(con))

# assert that creating a `tables` accessor object doesn't increase the
# number of strong references
assert after == before


@pytest.mark.parametrize(
"expr_fn",
[
Expand Down

0 comments on commit f97d704

Please sign in to comment.