diff --git a/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs b/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs index eac7f6efa8..0270f77904 100644 --- a/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs +++ b/src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs @@ -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); } } diff --git a/src/Umbraco.Infrastructure/Search/ExamineComponent.cs b/src/Umbraco.Infrastructure/Search/ExamineComponent.cs index f9db97b308..30dc01dc9a 100644 --- a/src/Umbraco.Infrastructure/Search/ExamineComponent.cs +++ b/src/Umbraco.Infrastructure/Search/ExamineComponent.cs @@ -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>> { - // 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>> - { - [true] = new Lazy>(() => examineComponent._publishedContentValueSetBuilder.GetValueSets(content).ToList()), - [false] = new Lazy>(() => examineComponent._contentValueSetBuilder.GetValueSets(content).ToList()) - }; + [true] = new Lazy>(() => examineComponent._publishedContentValueSetBuilder.GetValueSets(content).ToList()), + [false] = new Lazy>(() => examineComponent._contentValueSetBuilder.GetValueSets(content).ToList()) + }; - foreach (IUmbracoIndex index in examineComponent._examineManager.Indexes.OfType() - //filter the indexers - .Where(x => isPublished || !x.PublishedValuesOnly) - .Where(x => x.EnableDefaultEventHandler)) - { - List valueSet = builders[index.PublishedValuesOnly].Value; - index.IndexItems(valueSet); - } + foreach (IUmbracoIndex index in examineComponent._examineManager.Indexes.OfType() + //filter the indexers + .Where(x => isPublished || !x.PublishedValuesOnly) + .Where(x => x.EnableDefaultEventHandler)) + { + List valueSet = builders[index.PublishedValuesOnly].Value; + index.IndexItems(valueSet); } + return Task.CompletedTask; }); } diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs index f3efc16ece..3b1cbc06ca 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs @@ -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(() => - 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(() => - 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()) diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 6e9a38a56c..1bce8edcac 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -114,13 +114,11 @@ - - @@ -130,9 +128,7 @@ - - diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 03bc1ad6c2..5bb4ab72d3 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -67,7 +67,6 @@ - 5.0.376