Initialize important services before unattended installs (#17366)
* Added new notification to hook in after the premigrations and use this to init different services. * Force MaxDegreeOfParallelism to 1, while investigating scopes * Tried some more workarounds * Updated scopes and changed parallel to non parallel to ensure migration works * Missing scope * Make it parallel again - The secret is, the SuppressFlow needs to be when you create the task, but not on the await!. * Fixed issue when DEBUG_SCOPES is not added to tests. * Remove test exception * Try build on ubuntu again, even that we know it can be stuck. Just a test to see if all tests pass * Updated comment --------- Co-authored-by: kjac <kja@umbraco.dk>
This commit is contained in:
@@ -172,7 +172,7 @@ public abstract class UmbracoIntegrationTest : UmbracoIntegrationTestBase
|
||||
.AddCoreMappingProfiles();
|
||||
}
|
||||
|
||||
services.RemoveAll(x=>x.ImplementationType == typeof(DocumentUrlServiceInitializer));
|
||||
services.RemoveAll(x=>x.ImplementationType == typeof(DocumentUrlServiceInitializerNotificationHandler));
|
||||
services.AddSignalR();
|
||||
services.AddMvc();
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public abstract class UmbracoIntegrationTestWithContent : UmbracoIntegrationTest
|
||||
protected ContentType ContentType { get; private set; }
|
||||
|
||||
[SetUp]
|
||||
public void Setup() => CreateTestData();
|
||||
public virtual void Setup() => CreateTestData();
|
||||
|
||||
public virtual void CreateTestData()
|
||||
{
|
||||
|
||||
@@ -1,23 +1,13 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Cache;
|
||||
using Umbraco.Cms.Core.Handlers;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentEditing;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Sync;
|
||||
using Umbraco.Cms.Infrastructure.DependencyInjection;
|
||||
using Umbraco.Cms.Infrastructure.Examine;
|
||||
using Umbraco.Cms.Infrastructure.Examine.DependencyInjection;
|
||||
using Umbraco.Cms.Infrastructure.HostedServices;
|
||||
using Umbraco.Cms.Infrastructure.Search;
|
||||
using Umbraco.Cms.Tests.Common.Attributes;
|
||||
using Umbraco.Cms.Tests.Common.Builders;
|
||||
using Umbraco.Cms.Tests.Common.Testing;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
using Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping;
|
||||
using Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
@@ -33,12 +23,15 @@ public class DocumentUrlServiceTest : UmbracoIntegrationTestWithContent
|
||||
builder.Services.AddUnique<IServerMessenger, ScopedRepositoryTests.LocalServerMessenger>();
|
||||
builder.AddNotificationHandler<ContentTreeChangeNotification, ContentTreeChangeDistributedCacheNotificationHandler>();
|
||||
|
||||
builder.Services.AddHostedService<DocumentUrlServiceInitializer>();
|
||||
|
||||
builder.Services.AddNotificationAsyncHandler<UmbracoApplicationStartingNotification, DocumentUrlServiceInitializerNotificationHandler>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
DocumentUrlService.InitAsync(false, CancellationToken.None).GetAwaiter().GetResult();
|
||||
base.Setup();
|
||||
}
|
||||
//
|
||||
// [Test]
|
||||
// [LongRunning]
|
||||
|
||||
@@ -29,8 +29,14 @@ public class DocumentUrlServiceTest_HideTopLevel_False : UmbracoIntegrationTestW
|
||||
builder.Services.AddUnique<IServerMessenger, ScopedRepositoryTests.LocalServerMessenger>();
|
||||
builder.AddNotificationHandler<ContentTreeChangeNotification, ContentTreeChangeDistributedCacheNotificationHandler>();
|
||||
|
||||
builder.Services.AddHostedService<DocumentUrlServiceInitializer>();
|
||||
}
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
DocumentUrlService.InitAsync(false, CancellationToken.None).GetAwaiter().GetResult();
|
||||
base.Setup();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase("/textpage/", "en-US", true, ExpectedResult = TextpageKey)]
|
||||
[TestCase("/textpage/text-page-1", "en-US", true, ExpectedResult = SubPageKey)]
|
||||
|
||||
@@ -5,13 +5,11 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Cache;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentEditing;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.Security;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Sync;
|
||||
using Umbraco.Cms.Infrastructure.Examine;
|
||||
using Umbraco.Cms.Infrastructure.Examine.DependencyInjection;
|
||||
using Umbraco.Cms.Infrastructure.HostedServices;
|
||||
@@ -19,8 +17,6 @@ using Umbraco.Cms.Infrastructure.Search;
|
||||
using Umbraco.Cms.Tests.Common.Builders;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Cms.Tests.Common.Testing;
|
||||
using Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping;
|
||||
using Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
||||
using Umbraco.Cms.Web.Common.Security;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Examine.Lucene.UmbracoExamine;
|
||||
@@ -37,7 +33,9 @@ public class BackOfficeExamineSearcherTests : ExamineBaseTest
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.RequestServices = Services;
|
||||
Mock.Get(TestHelper.GetHttpContextAccessor()).Setup(x => x.HttpContext).Returns(httpContext);
|
||||
}
|
||||
|
||||
DocumentUrlService.InitAsync(false, CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
@@ -48,6 +46,7 @@ public class BackOfficeExamineSearcherTests : ExamineBaseTest
|
||||
Services.DisposeIfDisposable();
|
||||
}
|
||||
|
||||
private IDocumentUrlService DocumentUrlService => GetRequiredService<IDocumentUrlService>();
|
||||
private IBackOfficeExamineSearcher BackOfficeExamineSearcher => GetRequiredService<IBackOfficeExamineSearcher>();
|
||||
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
|
||||
@@ -44,9 +44,8 @@ public abstract class ExamineBaseTest : UmbracoIntegrationTest
|
||||
builder
|
||||
.AddNotificationHandler<ContentTreeChangeNotification,
|
||||
ContentTreeChangeDistributedCacheNotificationHandler>();
|
||||
builder.Services.AddHostedService<DocumentUrlServiceInitializer>();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to create and manage a testable index
|
||||
/// </summary>
|
||||
|
||||
@@ -37,6 +37,8 @@ public class ExamineExternalIndexTests : ExamineBaseTest
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.RequestServices = Services;
|
||||
Mock.Get(TestHelper.GetHttpContextAccessor()).Setup(x => x.HttpContext).Returns(httpContext);
|
||||
|
||||
DocumentUrlService.InitAsync(false, CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -52,6 +54,7 @@ public class ExamineExternalIndexTests : ExamineBaseTest
|
||||
private IExamineExternalIndexSearcherTest ExamineExternalIndexSearcher =>
|
||||
GetRequiredService<IExamineExternalIndexSearcherTest>();
|
||||
|
||||
private IDocumentUrlService DocumentUrlService => GetRequiredService<IDocumentUrlService>();
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
|
||||
private ContentService ContentService => (ContentService)GetRequiredService<IContentService>();
|
||||
|
||||
@@ -3,6 +3,7 @@ using Examine;
|
||||
using Lucene.Net.Util;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Infrastructure.Examine;
|
||||
using Umbraco.Cms.Tests.Common.Attributes;
|
||||
using Umbraco.Cms.Tests.Common.Builders;
|
||||
@@ -18,6 +19,15 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Examine.Lucene.UmbracoExamine;
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
|
||||
public class IndexTest : ExamineBaseTest
|
||||
{
|
||||
private IDocumentUrlService DocumentUrlService => GetRequiredService<IDocumentUrlService>();
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
DocumentUrlService.InitAsync(false, CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[LongRunning]
|
||||
public void GivenValidationParentNode_WhenContentIndexedUnderDifferentParent_DocumentIsNotIndexed()
|
||||
|
||||
@@ -18,6 +18,15 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Examine.Lucene.UmbracoExamine;
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, Logger = UmbracoTestOptions.Logger.Console)]
|
||||
public class SearchTests : ExamineBaseTest
|
||||
{
|
||||
private IDocumentUrlService DocumentUrlService => GetRequiredService<IDocumentUrlService>();
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
DocumentUrlService.InitAsync(false, CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[LongRunning]
|
||||
public void Test_Sort_Order_Sorting()
|
||||
|
||||
@@ -52,14 +52,14 @@ public class MigrationTests
|
||||
|
||||
public ISqlContext SqlContext { get; set; }
|
||||
|
||||
#if DEBUG_SCOPES
|
||||
public ScopeInfo GetScopeInfo(IScope scope)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public IEnumerable<ScopeInfo> ScopeInfos => throw new NotImplementedException();
|
||||
#endif
|
||||
public IScope AmbientScope { get; }
|
||||
|
||||
#if DEBUG_SCOPES
|
||||
public IEnumerable<ScopeInfo> ScopeInfos => throw new NotImplementedException();
|
||||
|
||||
public ScopeInfo GetScopeInfo(IScope scope) => throw new NotImplementedException();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
private class TestPlan : MigrationPlan
|
||||
|
||||
Reference in New Issue
Block a user