File tree Expand file tree Collapse file tree 4 files changed +21
-7
lines changed
EntityFramework.Exceptions/Tests Expand file tree Collapse file tree 4 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,6 @@ public interface IDbExceptionClassifier
99 public bool IsNumericOverflowError ( DbException exception ) ;
1010 public bool IsUniqueConstraintError ( DbException exception ) ;
1111 public bool IsMaxLengthExceededError ( DbException exception ) ;
12- public bool IsDeadlockError ( DbException exception ) => false ;
12+ public bool IsDeadlockError ( DbException exception ) ;
1313 }
1414}
Original file line number Diff line number Diff line change @@ -19,4 +19,6 @@ public bool IsUniqueConstraintError(DbException exception) => exception is Sqlit
1919 } ;
2020
2121 public bool IsMaxLengthExceededError ( DbException exception ) => exception is SqliteException { SqliteExtendedErrorCode : SQLITE_TOOBIG } ;
22+
23+ public bool IsDeadlockError ( DbException exception ) => exception is SqliteException { SqliteExtendedErrorCode : SQLITE_LOCKED_SHAREDCACHE } ;
2224}
Original file line number Diff line number Diff line change @@ -359,9 +359,9 @@ public virtual async Task Deadlock()
359359 var id1 = p1 . Entity . Id ;
360360 var id2 = p2 . Entity . Id ;
361361
362- using var controlContext = new DemoContext ( DemoContext . Options ) ;
363- using var transaction1 = await DemoContext . Database . BeginTransactionAsync ( ) ;
364- using var transaction2 = await controlContext . Database . BeginTransactionAsync ( ) ;
362+ await using var controlContext = new DemoContext ( DemoContext . Options ) ;
363+ await using var transaction1 = await DemoContext . Database . BeginTransactionAsync ( ) ;
364+ await using var transaction2 = await controlContext . Database . BeginTransactionAsync ( ) ;
365365
366366 await DemoContext . Products . Where ( c => c . Id == id1 )
367367 . ExecuteUpdateAsync ( c => c . SetProperty ( p => p . Name , "Test11" ) ) ;
Original file line number Diff line number Diff line change 11using DotNet . Testcontainers . Containers ;
2+ using EntityFramework . Exceptions . Common ;
23using EntityFramework . Exceptions . Sqlite ;
34using Microsoft . Data . Sqlite ;
45using Microsoft . EntityFrameworkCore ;
56using SQLitePCL ;
7+ using System . Linq ;
68using System . Runtime . InteropServices ;
79using System . Threading . Tasks ;
810using Xunit ;
@@ -53,10 +55,20 @@ public override Task NumericOverflowViolationThrowsNumericOverflowExceptionThrou
5355 return Task . CompletedTask ;
5456 }
5557
56- [ Fact ( Skip = "Skipping as SQLite no deadlock." ) ]
57- public override Task Deadlock ( )
58+ [ Fact ]
59+ public override async Task Deadlock ( )
5860 {
59- return Task . CompletedTask ;
61+ var product = new Product { Name = "Test1" } ;
62+ DemoContext . Products . Add ( product ) ;
63+
64+ await DemoContext . SaveChangesAsync ( ) ;
65+
66+ await using var controlContext = new DemoContext ( DemoContext . Options ) ;
67+ await using var transaction1 = await DemoContext . Database . BeginTransactionAsync ( ) ;
68+
69+ await Assert . ThrowsAsync < DeadlockException > ( ( ) => controlContext . Products
70+ . Where ( c => c . Id == product . Id )
71+ . ExecuteUpdateAsync ( c => c . SetProperty ( p => p . Name , "Test12" ) ) ) ;
6072 }
6173 }
6274
You can’t perform that action at this time.
0 commit comments