Merge remote-tracking branch 'origin/v10/dev' into v11/dev

This commit is contained in:
Bjarke Berg
2024-03-15 14:55:56 +01:00
10 changed files with 129 additions and 38 deletions

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NPoco;
@@ -15,7 +10,6 @@ using Umbraco.Cms.Persistence.Sqlite.Interceptors;
using Umbraco.Cms.Tests.Common.Attributes;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
using Umbraco.Extensions;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence;
@@ -126,6 +120,7 @@ public class LocksTests : UmbracoIntegrationTest
}
}
[NUnit.Framework.Ignore("We currently do not have a way to force lazy locks")]
[Test]
public void GivenNonEagerLocking_WhenNoDbIsAccessed_ThenNoSqlIsExecuted()
{
@@ -155,6 +150,37 @@ public class LocksTests : UmbracoIntegrationTest
Assert.AreEqual(0, sqlCount);
}
[Test]
public void GivenNonEagerLocking_WhenDbIsAccessed_ThenSqlIsExecuted()
{
var sqlCount = 0;
using (var scope = ScopeProvider.CreateScope())
{
var db = ScopeAccessor.AmbientScope.Database;
try
{
db.EnableSqlCount = true;
// Issue a lock request, but we are using non-eager
// locks so this only queues the request.
// The lock will not be issued unless we resolve
// scope.Database
scope.WriteLock(Constants.Locks.Servers);
scope.Database.ExecuteScalar<int>("SELECT 1");
sqlCount = db.SqlCount;
}
finally
{
db.EnableSqlCount = false;
}
}
Assert.AreEqual(2,sqlCount);
}
[Test]
[LongRunning]
public void ConcurrentWritersTest()