Skip to content

Add strategy with serializable transaction#132

Open
leoarnold wants to merge 1 commit intoDatabaseCleaner:mainfrom
leoarnold:leoarnold/serializable
Open

Add strategy with serializable transaction#132
leoarnold wants to merge 1 commit intoDatabaseCleaner:mainfrom
leoarnold:leoarnold/serializable

Conversation

@leoarnold
Copy link
Copy Markdown

Sometimes you need to use a serializable transaction, e.g. to implement a pessimistic "find or create"
as explained in this blog post.

In this case, we cannot clean with the Transaction strategy because we cannot nest a serializable transaction into a normal one.

We could clean with truncation, but that slows test down dramatically.

Starting with Rails v8.1.0, we can nest a transaction into transaction of the same isolation level.

This adds a cleaning strategy based on a serializable transaction.

Sometimes you need to use a serializable transaction,
e.g. to implement a pessimistic "find or create"
as explained in [this blog post](https://drmaciver.com/2013/02/implementing-find_or_create-correctly-is-impossible/).

In this case, we cannot clean with the Transaction strategy
because we cannot nest a serializable transaction into a normal one.

We could clean with truncation, but that slows test down dramatically.

Starting with Rails v8.1.0, we can nest a transaction into transaction
of the same isolation level.

This adds a cleaning strategy based on a serializable transaction.
@leoarnold
Copy link
Copy Markdown
Author

Note: The following PRs should be merged for this one to pass CI:

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.

1 participant