Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1564 concurrency conflicts bug #1565

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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