Path: redb/redb.Tests.Integration/Tests/Unit/RollbackAfterFailureTests.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/Unit/RollbackAfterFailureTests.cs ---- using System; using System.Threading.Tasks; using redb.Core.Data; namespace redb.Tests.Integration.Tests.Unit; /// /// A rollback after failed work must not replace the failure. On SQL Server a timeout or a deadlock victim ends the /// transaction on the server, the client's rollback then throws "This SqlTransaction has completed", and that error used /// to surface instead of the SqlException. The original is rethrown as it was; the rollback error rides on its Data. /// No database required. /// public class RollbackAfterFailureTests { [Fact] public async Task FailedRollback_IsAttached_AndTheOriginalStaysTheOneToRethrow() { var original = new TimeoutException("the work failed"); var rollbackFailure = new InvalidOperationException("This SqlTransaction has completed; it is no longer usable."); await RollbackAfterFailure.RollbackAsync(new Transaction(rollbackFailure), original); original.Data[RollbackAfterFailure.DataKey].Should().BeSameAs(rollbackFailure); } [Fact] public async Task SuccessfulRollback_LeavesTheOriginalUntouched() { var original = new TimeoutException("the work failed"); var transaction = new Transaction(null); await RollbackAfterFailure.RollbackAsync(transaction, original); transaction.RolledBack.Should().BeTrue(); original.Data.Contains(RollbackAfterFailure.DataKey).Should().BeFalse(); } private sealed class Transaction(Exception? rollbackFailure) : IRedbTransaction { public bool RolledBack { get; private set; } public Guid TransactionId { get; } = Guid.NewGuid(); public bool IsActive => !RolledBack; public DateTimeOffset StartedAt { get; } = DateTimeOffset.UtcNow; public Task CommitAsync() => Task.CompletedTask; public Task RollbackAsync() { if (rollbackFailure != null) throw rollbackFailure; RolledBack = true; return Task.CompletedTask; } public ValueTask DisposeAsync() => ValueTask.CompletedTask; } }