Skip to content

test: rollback transaction in tests relying on Spanner emulator#2045

Merged
chenba merged 12 commits intomasterfrom
test/rollback-spanner-emulator-transaction-STOR-388
Feb 13, 2026
Merged

test: rollback transaction in tests relying on Spanner emulator#2045
chenba merged 12 commits intomasterfrom
test/rollback-spanner-emulator-transaction-STOR-388

Conversation

@chenba
Copy link
Collaborator

@chenba chenba commented Feb 6, 2026

We need to explicitly rollback transactions in tests that rely on the Spanner emulator.

Closes STOR-388 / #1850

@chenba chenba force-pushed the test/rollback-spanner-emulator-transaction-STOR-388 branch 3 times, most recently from f01fec1 to bb5146f Compare February 6, 2026 23:13
@chenba chenba marked this pull request as ready for review February 7, 2026 02:11
@chenba chenba requested review from pjenvey and taddes February 7, 2026 02:11
Copy link
Member

@pjenvey pjenvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original issue I had an idea for making a wrapper similar to db_pool.transaction_http/http -- do you think that's feasible?

It would be more explicit than requiring the Drop and requiring the tests to call rollback themselves. One issue with the manual rollback is if any part of the test fails for whatever reason, that rollback won't be called.

It could be a noop on the backends that support test_transactions or it could replace that feature entirely.

@chenba
Copy link
Collaborator Author

chenba commented Feb 9, 2026

In the original issue I had an idea for making a wrapper similar to db_pool.transaction_http/http -- do you think that's feasible?

I'll take a look.

It would be more explicit than requiring the Drop and requiring the tests to call rollback themselves. One issue with the manual rollback is if any part of the test fails for whatever reason, that rollback won't be called.

I misinterpreted your request for making things explicit. Drop works without the other changes. As it is in this PR, the Drop is conditional so that if the test failed to rollback then Drop handles it. But we could just as well remove the "explicit" rollback in the test and let Drop handle it every time.

@chenba chenba marked this pull request as draft February 9, 2026 21:55
@chenba chenba force-pushed the test/rollback-spanner-emulator-transaction-STOR-388 branch 2 times, most recently from 68707f9 to c7d47f6 Compare February 11, 2026 18:38
@chenba
Copy link
Collaborator Author

chenba commented Feb 11, 2026

Added with_transaction, similar to db_pool.transaction_http, that wraps a test in a transaction, and ensures the rollback. The test updates are mostly whitespace from the additional indentation. h/t @pjenvey

@chenba chenba force-pushed the test/rollback-spanner-emulator-transaction-STOR-388 branch 3 times, most recently from 028653e to d038c8c Compare February 11, 2026 20:31
@chenba chenba force-pushed the test/rollback-spanner-emulator-transaction-STOR-388 branch from d038c8c to a30916c Compare February 11, 2026 20:36
@chenba chenba marked this pull request as ready for review February 11, 2026 21:29
@chenba chenba requested a review from pjenvey February 11, 2026 21:29
Copy link
Member

@pjenvey pjenvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, thanks for this


Ok(())
with_transaction(
Some(settings.clone()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit/not blocking this PR/more of an FYI: there's a Rust idiom where you can avoid the need for Some() here: Into<Option<_>>


/// Wrap a test in a DB transaction that will be rolled back. Read-only tests
/// do not need this.
pub async fn with_transaction<T>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this test_transaction or with_test_transaction? Especially as it's along similar lines of the use_test_transactions setting which calls diesel's begin_test_transaction.

Which reminds me, diesel even has essentially its own version of this it just calls test_transaction FYI

chenba and others added 2 commits February 12, 2026 11:09
Co-authored-by: Philip Jenvey <pjenvey@underboss.org>
@chenba chenba force-pushed the test/rollback-spanner-emulator-transaction-STOR-388 branch from 58a5948 to 026f54e Compare February 12, 2026 19:46
@chenba chenba requested a review from pjenvey February 12, 2026 21:31
@chenba chenba merged commit 6c6c0ff into master Feb 13, 2026
29 checks passed
@chenba chenba deleted the test/rollback-spanner-emulator-transaction-STOR-388 branch February 13, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants