Commit 82439b2
authored
Fix pytest hanging when test fails by closing PostgreSQL connection using
This patch depends on #70.
The pytest may hang when some of the test fails. This is a workflow run that exhibited this problem: https://github.com/apache/sedona-db/actions/runs/17668086933/job/50213528921
Pytest does not free up resources held by local variables by calling `__del__` in time when a test fails. When pytest captured the AssertionError, it effectively adds a reference to the local c object, preventing it from being __del__-ed when the function ends. This leaves the transaction started by the failed test active when the next test starts running.
We generate test data by dropping a temporary table, inserting data into the temporary table, and finally renaming the temporary table. Dropping the temporary table will be blocked by a lock held by the still-active transaction started by the previously failed test:
```
postgres=# select pid, query, state, wait_event, wait_event_type, backend_type from pg_stat_activity;
pid | query | state | wait_event | wait_event_type | backend_type
-------+--------------------------------------------------------------------------------------------+---------------------+---------------------+-----------------+------------------------------
99895 | | | AutoVacuumMain | Activity | autovacuum launcher
99896 | | | LogicalLauncherMain | Activity | logical replication launcher
83813 | select pid, query, state, wait_event, wait_event_type, backend_type from pg_stat_activity; | active | | | client backend
47073 | DROP TABLE IF EXISTS "public" . "sjoin_polygon_xtemp" | idle in transaction | ClientRead | Client | client backend
51565 | DROP TABLE IF EXISTS "public" . "sjoin_point_xtemp" | active | relation | Lock | client backend
66330 | DROP TABLE IF EXISTS "public" . "sjoin_point_xtemp" | active | relation | Lock | client backend
71494 | DROP TABLE IF EXISTS "public" . "sjoin_point_xtemp" | active | relation | Lock | client backend
99892 | | | BgWriterHibernate | Activity | background writer
99891 | | | CheckpointerMain | Activity | checkpointer
99894 | | | WalWriterMain | Activity | walwriter
```
This patch fixes this problem by managing connections using `with` statement. The transaction will be committed or rolled back when the connection is closed. This prevents us from leaking transactions and blocking ourselves on table locks.with statement (#71)1 parent 2be2f35 commit 82439b2
File tree
4 files changed
+666
-637
lines changed- python/sedonadb
- python/sedonadb
- tests
4 files changed
+666
-637
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
66 | 77 | | |
67 | 78 | | |
68 | 79 | | |
| |||
399 | 410 | | |
400 | 411 | | |
401 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
402 | 418 | | |
403 | 419 | | |
404 | 420 | | |
| |||
0 commit comments