MCPcopy
hub / github.com/psycopg/psycopg / test_leak

Function test_leak

tests/test_cursor_client.py:83–116  ·  view source on GitHub ↗
(conn_cls, dsn, faker, fetch, row_factory, gc)

Source from the content-addressed store, hash-verified

81@pytest.mark.parametrize("fetch", ["one", "many", "all", "iter"])
82@pytest.mark.parametrize("row_factory", ["tuple_row", "dict_row", "namedtuple_row"])
83def test_leak(conn_cls, dsn, faker, fetch, row_factory, gc):
84 faker.choose_schema(ncols=5)
85 faker.make_records(10)
86 row_factory = getattr(rows, row_factory)
87
88 def work():
89 with conn_cls.connect(dsn) as conn, conn.transaction(force_rollback=True):
90 with psycopg.ClientCursor(conn, row_factory=row_factory) as cur:
91 cur.execute(faker.drop_stmt)
92 cur.execute(faker.create_stmt)
93 with faker.find_insert_problem(conn):
94 cur.executemany(faker.insert_stmt, faker.records)
95 cur.execute(faker.select_stmt)
96
97 if fetch == "one":
98 while cur.fetchone() is not None:
99 pass
100 elif fetch == "many":
101 while cur.fetchmany(3):
102 pass
103 elif fetch == "all":
104 cur.fetchall()
105 elif fetch == "iter":
106 for rec in cur:
107 pass
108
109 n = []
110 gc.collect()
111 for i in range(3):
112 work()
113 gc.collect()
114 n.append(gc.count())
115
116 assert n[0] == n[1] == n[2], f"objects leaked: {n[1] - n[0]}, {n[2] - n[1]}"
117
118
119@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 5

choose_schemaMethod · 0.80
make_recordsMethod · 0.80
collectMethod · 0.80
countMethod · 0.80
workFunction · 0.70

Tested by

no test coverage detected