Skip to content

Commit

Permalink
Merge pull request #1565 from qdraw/feature/202404-1564-concurrency-c…
Browse files Browse the repository at this point in the history
…onflicts

#1564 concurrency conflicts bug
  • Loading branch information
qdraw authored Apr 26, 2024
2 parents 4c6d381 + c723cec commit d8f4126
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Semantic Versioning 2.0.0 is from version 0.1.6+
- [x] (Changed) Back-end Upgrade to .NET 8 - SDK 8.0.204 (Runtime: 8.0.4) (PR #1541)
- [x] (Fixed) _Back-end_ Unhandled exception DbUpdateException (PR #1558 Issue #1489)
- [x] (Fixed) _Back-end_ Regex timeout IsExtensionForce (PR #1542 Issue #1537)
- [x] (Fixed) _Back-end_ Concurrency conflicts bug (PR #1565 Issue #1564)

## version 0.6.0 - 2024-03-15 {#v0.6.0}

Expand Down
16 changes: 12 additions & 4 deletions starsky/starsky.foundation.database/Query/SolveConcurrency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ namespace starsky.foundation.database.Query
{
public static class SolveConcurrency
{
/// <summary>
/// Make sure you add the right type in the check
/// </summary>
/// <param name="concurrencyExceptionEntries">Entry items</param>
internal static void SolveConcurrencyExceptionLoop(
IReadOnlyList<EntityEntry> concurrencyExceptionEntries)
{
Expand All @@ -29,20 +33,24 @@ internal static void SolveConcurrencyExceptionLoop(
/// Database concurrency refers to situations in which multiple processes or users access or change the same data in a database at the same time.
/// @see: https://docs.microsoft.com/en-us/ef/core/saving/concurrency
/// </summary>
/// <param name="entryEntity">item</param>
/// <param name="_">item</param>
/// <param name="proposedValues">new update</param>
/// <param name="databaseValues">old database item</param>
/// <param name="entryMetadataName">meta name</param>
/// <param name="entryOriginalValuesSetValues">entry item</param>
/// <exception cref="NotSupportedException">unknown how to fix</exception>
internal static void SolveConcurrencyException(object entryEntity,
internal static void SolveConcurrencyException(object _,
PropertyValues proposedValues, PropertyValues? databaseValues, string entryMetadataName,
OriginalValuesSetValuesDelegate entryOriginalValuesSetValues)
{
if ( !( entryEntity is FileIndexItem ) )
if ( _ is not FileIndexItem &&
_ is not ThumbnailItem &&
_ is not NotificationItem)
{
throw new NotSupportedException(
"Don't know how to handle concurrency conflicts for "
"[SolveConcurrency] Don't know how to handle concurrency conflicts for "
+ entryMetadataName);
}

foreach ( var property in proposedValues.Properties )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,7 @@ public override object? this[IProperty property]
public void SolveConcurrencyException_should_callDelegate()
{
SolveConcurrency.SolveConcurrencyException(new FileIndexItem(),
#pragma warning disable 8625
new FakePropertyValues(null), new FakePropertyValues(null),
#pragma warning restore 8625
new FakePropertyValues(null!), new FakePropertyValues(null!),
"", _ => IsWrittenConcurrencyException = true);

Assert.IsTrue(IsCalledDbUpdateConcurrency);
Expand All @@ -519,14 +517,11 @@ public void SolveConcurrencyException_should_callDelegate()
public void Query_UpdateItem_NotSupportedException()
{
SolveConcurrency.SolveConcurrencyException(null!,
#pragma warning disable 8625
new FakePropertyValues(null), new FakePropertyValues(null),
#pragma warning restore 8625
new FakePropertyValues(null!), new FakePropertyValues(null!),
"", _ => IsWrittenConcurrencyException = true);
// expect error
}


private class AppDbInvalidOperationException : ApplicationDbContext
{
public AppDbInvalidOperationException(DbContextOptions options) : base(options)
Expand Down Expand Up @@ -722,7 +717,8 @@ public async Task Query_AddRangeAsync_DoubleConcurrencyException()
};

await fakeQuery.AddRangeAsync(fileIndexItemList);

await fakeQuery.AddRangeAsync(fileIndexItemList);

Assert.IsTrue(IsCalledDbUpdateConcurrency);
}

Expand Down

0 comments on commit d8f4126

Please sign in to comment.