Migrated ReportSite, OpenIddictCleanup and TemporaryFileCleanup to background jobs (#15555)

* Migrated ReportSite, OpenIddictCleanup and TemporaryFileCleanup to the new background jobs introduced in v13.

* Fixed delay and period
This commit is contained in:
Bjarke Berg
2024-01-11 13:18:10 +01:00
committed by GitHub
parent 416c19854d
commit e291fae01e
24 changed files with 79 additions and 2020 deletions

View File

@@ -8,6 +8,7 @@ using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Runtime;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs;
using Umbraco.Cms.Infrastructure.HostedServices;
using Umbraco.Cms.Tests.UnitTests.AutoFixture;
@@ -24,7 +25,7 @@ internal class ContentVersionCleanupTest
[Frozen] Mock<IServerRoleAccessor> serverRoleAccessor,
[Frozen] Mock<IRuntimeState> runtimeState,
[Frozen] Mock<IContentVersionService> cleanupService,
ContentVersionCleanup sut)
ContentVersionCleanupJob sut)
{
settings.Setup(x => x.CurrentValue).Returns(new ContentSettings
{
@@ -34,77 +35,7 @@ internal class ContentVersionCleanupTest
mainDom.Setup(x => x.IsMainDom).Returns(true);
serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher);
await sut.PerformExecuteAsync(null);
cleanupService.Verify(x => x.PerformContentVersionCleanup(It.IsAny<DateTime>()), Times.Never);
}
[Test]
[AutoMoqData]
public async Task ContentVersionCleanup_RuntimeLevelNotRun_DoesNotCleanupWillRepeat(
[Frozen] Mock<IOptionsMonitor<ContentSettings>> settings,
[Frozen] Mock<IMainDom> mainDom,
[Frozen] Mock<IServerRoleAccessor> serverRoleAccessor,
[Frozen] Mock<IRuntimeState> runtimeState,
[Frozen] Mock<IContentVersionService> cleanupService,
ContentVersionCleanup sut)
{
settings.Setup(x => x.CurrentValue).Returns(new ContentSettings
{
ContentVersionCleanupPolicy = new ContentVersionCleanupPolicySettings { EnableCleanup = true },
});
runtimeState.Setup(x => x.Level).Returns(RuntimeLevel.Unknown);
mainDom.Setup(x => x.IsMainDom).Returns(true);
serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher);
await sut.PerformExecuteAsync(null);
cleanupService.Verify(x => x.PerformContentVersionCleanup(It.IsAny<DateTime>()), Times.Never);
}
[Test]
[AutoMoqData]
public async Task ContentVersionCleanup_ServerRoleUnknown_DoesNotCleanupWillRepeat(
[Frozen] Mock<IOptionsMonitor<ContentSettings>> settings,
[Frozen] Mock<IMainDom> mainDom,
[Frozen] Mock<IServerRoleAccessor> serverRoleAccessor,
[Frozen] Mock<IRuntimeState> runtimeState,
[Frozen] Mock<IContentVersionService> cleanupService,
ContentVersionCleanup sut)
{
settings.Setup(x => x.CurrentValue).Returns(new ContentSettings
{
ContentVersionCleanupPolicy = new ContentVersionCleanupPolicySettings { EnableCleanup = true },
});
runtimeState.Setup(x => x.Level).Returns(RuntimeLevel.Run);
mainDom.Setup(x => x.IsMainDom).Returns(true);
serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.Unknown);
await sut.PerformExecuteAsync(null);
cleanupService.Verify(x => x.PerformContentVersionCleanup(It.IsAny<DateTime>()), Times.Never);
}
[Test]
[AutoMoqData]
public async Task ContentVersionCleanup_NotMainDom_DoesNotCleanupWillNotRepeat(
[Frozen] Mock<IOptionsMonitor<ContentSettings>> settings,
[Frozen] Mock<IMainDom> mainDom,
[Frozen] Mock<IServerRoleAccessor> serverRoleAccessor,
[Frozen] Mock<IRuntimeState> runtimeState,
[Frozen] Mock<IContentVersionService> cleanupService,
ContentVersionCleanup sut)
{
settings.Setup(x => x.CurrentValue).Returns(new ContentSettings
{
ContentVersionCleanupPolicy = new ContentVersionCleanupPolicySettings { EnableCleanup = true },
});
runtimeState.Setup(x => x.Level).Returns(RuntimeLevel.Run);
mainDom.Setup(x => x.IsMainDom).Returns(false);
serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher);
await sut.PerformExecuteAsync(null);
await sut.RunJobAsync();
cleanupService.Verify(x => x.PerformContentVersionCleanup(It.IsAny<DateTime>()), Times.Never);
}
@@ -117,7 +48,7 @@ internal class ContentVersionCleanupTest
[Frozen] Mock<IServerRoleAccessor> serverRoleAccessor,
[Frozen] Mock<IRuntimeState> runtimeState,
[Frozen] Mock<IContentVersionService> cleanupService,
ContentVersionCleanup sut)
ContentVersionCleanupJob sut)
{
settings.Setup(x => x.CurrentValue).Returns(new ContentSettings
{
@@ -128,7 +59,7 @@ internal class ContentVersionCleanupTest
mainDom.Setup(x => x.IsMainDom).Returns(true);
serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher);
await sut.PerformExecuteAsync(null);
await sut.RunJobAsync();
cleanupService.Verify(x => x.PerformContentVersionCleanup(It.IsAny<DateTime>()), Times.Once);
}