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

Function test_leak

tests/test_cursor_raw_async.py:76–110  ·  view source on GitHub ↗
(aconn_cls, dsn, faker, fmt, fmt_out, fetch, row_factory, gc)

Source from the content-addressed store, hash-verified

74@pytest.mark.parametrize("fetch", ["one", "many", "all", "iter"])
75@pytest.mark.parametrize("row_factory", ["tuple_row", "dict_row", "namedtuple_row"])
76async def test_leak(aconn_cls, dsn, faker, fmt, fmt_out, fetch, row_factory, gc):
77 faker.format = fmt
78 faker.choose_schema(ncols=5)
79 faker.make_records(10)
80 row_factory = getattr(rows, row_factory)
81
82 async def work():
83 async with await aconn_cls.connect(dsn) as aconn:
84 async with aconn.transaction(force_rollback=True):
85 async with aconn.cursor(binary=fmt_out, row_factory=row_factory) as cur:
86 await cur.execute(faker.drop_stmt)
87 await cur.execute(faker.create_stmt)
88 async with faker.find_insert_problem_async(aconn):
89 await cur.executemany(faker.insert_stmt, faker.records)
90 await cur.execute(ph(cur, faker.select_stmt))
91
92 if fetch == "one":
93 while (await cur.fetchone()) is not None:
94 pass
95 elif fetch == "many":
96 while await cur.fetchmany(3):
97 pass
98 elif fetch == "all":
99 await cur.fetchall()
100 elif fetch == "iter":
101 async for rec in cur:
102 pass
103
104 n = []
105 gc.collect()
106 for i in range(3):
107 await work()
108 gc.collect()
109 n.append(gc.count())
110 assert n[0] == n[1] == n[2], f"objects leaked: {n[1] - n[0]}, {n[2] - n[1]}"

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