A testing-only transaction manager which replaces nested transactions with savepoints

Open
#26,504 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
database

Research direction

Start by reading IDbContextTransactionManager and the existing transaction abstractions in EF Core, then review the related discussion in Npgsql issue 3982. Define how a testing-only manager would represent nested transactions as savepoints and prevent commits; done means integration tests can manage transactions, roll back safely, and run without database reset interference or disabled parallelization.

Written by the indexing model from the issue text.

Description

area-save-changes customer-reported

It is currently a bit challenging to write integration tests for (user) product code which explicitly manages transactions. Since database don't support nested transactions, users can't run the entire test in a transaction and roll it back (to avoid test interference, as can be done with tests which don't manage transactions). This causes the following difficulties:

  • The database needs to be reverted to its initial state after every test runs, which can be tricky.
  • Test parallelization must be disabled.

We could provide an IDbContextTransactionManager which "implements" nested transactions as savepoints. That is, if BeginTransaction is called and a transaction already exists, we could create a savepoint instead. This would allow the test to fully manage transactions, but without ever actually committing anything, working around the issues above.

Originally discussed in https://github.com/npgsql/npgsql/issues/3982

Dominant language
C#
Stars
14.8k
Forks
3.4k
Avg merge
2d 5h
Merged PRs (30d)
134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/efcore

All issues in dotnet/efcore

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.