Skip to content

Commit 2175fe7

Browse files
committed
Fix test failed.
1 parent cdf9494 commit 2175fe7

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

EntityFramework.Exceptions/Tests/DatabaseTests.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -360,27 +360,20 @@ public virtual async Task Deadlock()
360360
var id2 = p2.Entity.Id;
361361

362362
using var controlContext = new DemoContext(DemoContext.Options);
363-
using var transaction1 = DemoContext.Database.BeginTransactionAsync();
364-
using var transaction2 = controlContext.Database.BeginTransactionAsync();
363+
using var transaction1 = await DemoContext.Database.BeginTransactionAsync();
364+
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"));
368368

369-
await Assert.ThrowsAsync<DeadlockException>(async () =>
370-
{
371-
await controlContext.Products.Where(c => c.Id == id2)
372-
.ExecuteUpdateAsync(c => c.SetProperty(p => p.Name, "Test21"));
373-
374-
var task1 = Task.Run(() => DemoContext.Products.Where(c => c.Id == id2)
375-
.ExecuteUpdateAsync(c => c.SetProperty(p => p.Name, "Test22")));
376-
377-
await Task.Delay(100);
369+
await controlContext.Products.Where(c => c.Id == id2)
370+
.ExecuteUpdateAsync(c => c.SetProperty(p => p.Name, "Test21"));
378371

379-
var task2 = controlContext.Products.Where(c => c.Id == id1)
380-
.ExecuteUpdateAsync(c => c.SetProperty(p => p.Name, "Test12"));
381-
382-
await Task.WhenAll(task1, task2);
383-
});
372+
await Assert.ThrowsAsync<DeadlockException>(() => Task.WhenAll(Task.Run(() => DemoContext.Products
373+
.Where(c => c.Id == id2)
374+
.ExecuteUpdateAsync(c => c.SetProperty(p => p.Name, "Test22"))), controlContext.Products
375+
.Where(c => c.Id == id1)
376+
.ExecuteUpdateAsync(c => c.SetProperty(p => p.Name, "Test12"))));
384377
}
385378

386379
public virtual void Dispose()

0 commit comments

Comments
 (0)