Post merge fixes

This commit is contained in:
Bjarke Berg
2021-03-09 11:15:55 +01:00
parent 1aa8d3aa09
commit 9153715432
5 changed files with 17 additions and 175 deletions

View File

@@ -278,7 +278,7 @@ where tbl.[name]=@0 and col.[name]=@1;", tableName, columnName)
public override void WriteLock(IDatabase db, params int[] lockIds)
{
WriteLock(db, TimeSpan.FromSeconds(5), lockIds);
WriteLock(db, _globalSettings.Value.SqlWriteLockTimeOut, lockIds);
}
public void WriteLock(IDatabase db, TimeSpan timeout, params int[] lockIds)
@@ -302,7 +302,7 @@ where tbl.[name]=@0 and col.[name]=@1;", tableName, columnName)
foreach (var lockId in lockIds)
{
ObtainWriteLock(db, _globalSettings.Value.SqlWriteLockTimeOut, lockId);
ObtainWriteLock(db, timeout, lockId);
}
}

View File

@@ -687,27 +687,23 @@ namespace Umbraco.Cms.Infrastructure.Search
{
using IScope scope = examineComponent._scopeProvider.CreateScope(autoComplete: true);
// Background thread, wrap the whole thing in an explicit scope since we know
// DB services are used within this logic.
using (examineComponent._scopeProvider.CreateScope(autoComplete: true))
// for content we have a different builder for published vs unpublished
// we don't want to build more value sets than is needed so we'll lazily build 2 one for published one for non-published
var builders = new Dictionary<bool, Lazy<List<ValueSet>>>
{
// for content we have a different builder for published vs unpublished
// we don't want to build more value sets than is needed so we'll lazily build 2 one for published one for non-published
var builders = new Dictionary<bool, Lazy<List<ValueSet>>>
{
[true] = new Lazy<List<ValueSet>>(() => examineComponent._publishedContentValueSetBuilder.GetValueSets(content).ToList()),
[false] = new Lazy<List<ValueSet>>(() => examineComponent._contentValueSetBuilder.GetValueSets(content).ToList())
};
[true] = new Lazy<List<ValueSet>>(() => examineComponent._publishedContentValueSetBuilder.GetValueSets(content).ToList()),
[false] = new Lazy<List<ValueSet>>(() => examineComponent._contentValueSetBuilder.GetValueSets(content).ToList())
};
foreach (IUmbracoIndex index in examineComponent._examineManager.Indexes.OfType<IUmbracoIndex>()
//filter the indexers
.Where(x => isPublished || !x.PublishedValuesOnly)
.Where(x => x.EnableDefaultEventHandler))
{
List<ValueSet> valueSet = builders[index.PublishedValuesOnly].Value;
index.IndexItems(valueSet);
}
foreach (IUmbracoIndex index in examineComponent._examineManager.Indexes.OfType<IUmbracoIndex>()
//filter the indexers
.Where(x => isPublished || !x.PublishedValuesOnly)
.Where(x => x.EnableDefaultEventHandler))
{
List<ValueSet> valueSet = builders[index.PublishedValuesOnly].Value;
index.IndexItems(valueSet);
}
return Task.CompletedTask;
});
}

View File

@@ -1,18 +1,15 @@
using System;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using NPoco;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
using Constants = Umbraco.Cms.Core.Constants;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence
{
@@ -324,152 +321,6 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence
Assert.IsNull(e2);
}
[Test]
public void Throws_When_Lock_Timeout_Is_Exceeded()
{
var t1 = Task.Run(() =>
{
using (var scope = ScopeProvider.CreateScope())
{
var realScope = (Scope)scope;
Console.WriteLine("Write lock A");
// This will acquire right away
realScope.WriteLock(TimeSpan.FromMilliseconds(2000), Constants.Locks.ContentTree);
Thread.Sleep(6000); // Wait longer than the Read Lock B timeout
scope.Complete();
Console.WriteLine("Finished Write lock A");
}
});
Thread.Sleep(500); // 100% sure task 1 starts first
var t2 = Task.Run(() =>
{
using (var scope = ScopeProvider.CreateScope())
{
var realScope = (Scope)scope;
Console.WriteLine("Read lock B");
// This will wait for the write lock to release but it isn't going to wait long
// enough so an exception will be thrown.
Assert.Throws<SqlException>(() =>
realScope.ReadLock(TimeSpan.FromMilliseconds(3000), Constants.Locks.ContentTree));
scope.Complete();
Console.WriteLine("Finished Read lock B");
}
});
var t3 = Task.Run(() =>
{
using (var scope = ScopeProvider.CreateScope())
{
var realScope = (Scope)scope;
Console.WriteLine("Write lock C");
// This will wait for the write lock to release but it isn't going to wait long
// enough so an exception will be thrown.
Assert.Throws<SqlException>(() =>
realScope.WriteLock(TimeSpan.FromMilliseconds(3000), Constants.Locks.ContentTree));
scope.Complete();
Console.WriteLine("Finished Write lock C");
}
});
Task.WaitAll(t1, t2, t3);
}
[Test]
public void Read_Lock_Waits_For_Write_Lock()
{
var locksCompleted = 0;
var t1 = Task.Run(() =>
{
using (var scope = ScopeProvider.CreateScope())
{
var realScope = (Scope)scope;
Console.WriteLine("Write lock A");
// This will acquire right away
realScope.WriteLock(TimeSpan.FromMilliseconds(2000), Constants.Locks.ContentTree);
Thread.Sleep(4000); // Wait less than the Read Lock B timeout
scope.Complete();
Interlocked.Increment(ref locksCompleted);
Console.WriteLine("Finished Write lock A");
}
});
Thread.Sleep(500); // 100% sure task 1 starts first
var t2 = Task.Run(() =>
{
using (var scope = ScopeProvider.CreateScope())
{
var realScope = (Scope)scope;
Console.WriteLine("Read lock B");
// This will wait for the write lock to release
Assert.DoesNotThrow(() =>
realScope.ReadLock(TimeSpan.FromMilliseconds(6000), Constants.Locks.ContentTree));
Assert.GreaterOrEqual(locksCompleted, 1);
scope.Complete();
Interlocked.Increment(ref locksCompleted);
Console.WriteLine("Finished Read lock B");
}
});
var t3 = Task.Run(() =>
{
using (var scope = ScopeProvider.CreateScope())
{
var realScope = (Scope)scope;
Console.WriteLine("Read lock C");
// This will wait for the write lock to release
Assert.DoesNotThrow(() =>
realScope.ReadLock(TimeSpan.FromMilliseconds(6000), Constants.Locks.ContentTree));
Assert.GreaterOrEqual(locksCompleted, 1);
scope.Complete();
Interlocked.Increment(ref locksCompleted);
Console.WriteLine("Finished Read lock C");
}
});
Task.WaitAll(t1, t2, t3);
Assert.AreEqual(3, locksCompleted);
}
[Test]
[NUnit.Framework.Ignore("We cannot run this test with SQLCE because it does not support a Command Timeout")]
public void Lock_Exceeds_Command_Timeout()
{
using (var scope = ScopeProvider.CreateScope())
{
var realScope = (Scope)scope;
var realDb = (Database)realScope.Database;
realDb.CommandTimeout = 1000;
Console.WriteLine("Write lock A");
// TODO: In theory this would throw
realScope.WriteLock(TimeSpan.FromMilliseconds(3000), Constants.Locks.ContentTree);
scope.Complete();
Console.WriteLine("Finished Write lock A");
}
}
private void NoDeadLockTestThread(int id, EventWaitHandle myEv, WaitHandle otherEv, ref Exception exception)
{
using (var scope = ScopeProvider.CreateScope())

View File

@@ -114,13 +114,11 @@
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0.0" />
<PackageReference Include="MiniProfiler" Version="4.2.22" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="NPoco" Version="4.0.2" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="MiniProfiler" Version="4.0.138" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="NPoco" Version="3.9.4" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
<PackageReference Include="NPoco" Version="4.0.3" />
@@ -130,9 +128,7 @@
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
<PackageReference Include="Umbraco.SqlServerCE" Version="4.0.0.1" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" />
<PackageReference Include="Umbraco.SqlServerCE" Version="4.0.0.1" />
</ItemGroup>
<ItemGroup>

View File

@@ -67,7 +67,6 @@
</PackageReference>
<PackageReference Include="HtmlAgilityPack" Version="1.11.30" />
<PackageReference Include="CSharpTest.Net.Collections" Version="14.906.1403.1082" />
<PackageReference Include="HtmlAgilityPack" Version="1.8.14" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.31" />
<PackageReference Include="HtmlSanitizer">
<Version>5.0.376</Version>