Skip to content

Commit 003f204

Browse files
committed
Additional tests and clearer fixtures
1 parent 14b8444 commit 003f204

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

tests/integration/dbapi/async/V2/test_queries_async.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,3 +816,38 @@ async def test_transaction_rollback(
816816
await c.execute('SELECT * FROM "test_tbl" WHERE id = 1')
817817
data = await c.fetchall()
818818
assert len(data) == 0, "Rolled back data should not be present"
819+
820+
821+
async def test_transaction_cursor_isolation(
822+
connection: Connection, create_drop_test_table_setup_teardown_async: Callable
823+
) -> None:
824+
"""Test that one cursor can't see another's data until it commits."""
825+
cursor1 = connection.cursor()
826+
cursor2 = connection.cursor()
827+
828+
# Start transaction in cursor1 and insert data
829+
result = await cursor1.execute("BEGIN TRANSACTION")
830+
assert result == 0, "BEGIN TRANSACTION should return 0 rows"
831+
832+
await cursor1.execute("INSERT INTO \"test_tbl\" VALUES (1, 'isolated_data')")
833+
834+
# Verify cursor1 can see its own uncommitted data
835+
await cursor1.execute('SELECT * FROM "test_tbl" WHERE id = 1')
836+
data1 = await cursor1.fetchall()
837+
assert len(data1) == 1, "Cursor1 should see its own uncommitted data"
838+
assert data1[0] == [1, "isolated_data"], "Cursor1 data should match inserted values"
839+
840+
# Verify cursor2 cannot see cursor1's uncommitted data
841+
await cursor2.execute('SELECT * FROM "test_tbl" WHERE id = 1')
842+
data2 = await cursor2.fetchall()
843+
assert len(data2) == 0, "Cursor2 should not see cursor1's uncommitted data"
844+
845+
# Commit the transaction in cursor1
846+
result = await cursor1.execute("COMMIT TRANSACTION")
847+
assert result == 0, "COMMIT TRANSACTION should return 0 rows"
848+
849+
# Now cursor2 should be able to see the committed data
850+
await cursor2.execute('SELECT * FROM "test_tbl" WHERE id = 1')
851+
data2 = await cursor2.fetchall()
852+
assert len(data2) == 1, "Cursor2 should see committed data after commit"
853+
assert data2[0] == [1, "isolated_data"], "Cursor2 should see the committed data"

tests/integration/dbapi/sync/V2/test_queries.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,3 +817,38 @@ def test_transaction_rollback(
817817
c.execute('SELECT * FROM "test_tbl" WHERE id = 1')
818818
data = c.fetchall()
819819
assert len(data) == 0, "Rolled back data should not be present"
820+
821+
822+
def test_transaction_cursor_isolation(
823+
connection: Connection, create_drop_test_table_setup_teardown: Callable
824+
) -> None:
825+
"""Test that one cursor can't see another's data until it commits."""
826+
cursor1 = connection.cursor()
827+
cursor2 = connection.cursor()
828+
829+
# Start transaction in cursor1 and insert data
830+
result = cursor1.execute("BEGIN TRANSACTION")
831+
assert result == 0, "BEGIN TRANSACTION should return 0 rows"
832+
833+
cursor1.execute("INSERT INTO \"test_tbl\" VALUES (1, 'isolated_data')")
834+
835+
# Verify cursor1 can see its own uncommitted data
836+
cursor1.execute('SELECT * FROM "test_tbl" WHERE id = 1')
837+
data1 = cursor1.fetchall()
838+
assert len(data1) == 1, "Cursor1 should see its own uncommitted data"
839+
assert data1[0] == [1, "isolated_data"], "Cursor1 data should match inserted values"
840+
841+
# Verify cursor2 cannot see cursor1's uncommitted data
842+
cursor2.execute('SELECT * FROM "test_tbl" WHERE id = 1')
843+
data2 = cursor2.fetchall()
844+
assert len(data2) == 0, "Cursor2 should not see cursor1's uncommitted data"
845+
846+
# Commit the transaction in cursor1
847+
result = cursor1.execute("COMMIT TRANSACTION")
848+
assert result == 0, "COMMIT TRANSACTION should return 0 rows"
849+
850+
# Now cursor2 should be able to see the committed data
851+
cursor2.execute('SELECT * FROM "test_tbl" WHERE id = 1')
852+
data2 = cursor2.fetchall()
853+
assert len(data2) == 1, "Cursor2 should see committed data after commit"
854+
assert data2[0] == [1, "isolated_data"], "Cursor2 should see the committed data"

tests/unit/db_conftest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,14 @@ def do_query(request: Request, **kwargs) -> Response:
261261

262262

263263
@fixture
264-
def query_callback_with_remove_header(query_statistics: Dict[str, Any]) -> Callable:
264+
def remove_parameters() -> List[str]:
265+
return ["param1", "param3"]
266+
267+
268+
@fixture
269+
def query_callback_with_remove_header(
270+
query_statistics: Dict[str, Any], remove_parameters: List[str]
271+
) -> Callable:
265272
"""Fixture for query callback that returns REMOVE_PARAMETERS_HEADER.
266273
267274
Returns a callback that simulates a server response with Firebolt-Remove-Parameters
@@ -278,7 +285,7 @@ def do_query(request: Request, **kwargs) -> Response:
278285
"statistics": query_statistics,
279286
}
280287
# Header with comma-separated parameter names to remove
281-
headers = {"Firebolt-Remove-Parameters": "param1,param3"}
288+
headers = {"Firebolt-Remove-Parameters": ",".join(remove_parameters)}
282289
return Response(status_code=codes.OK, json=query_response, headers=headers)
283290

284291
return do_query

0 commit comments

Comments
 (0)