2021-03-08 17:13:37 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Core.Sync;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.Persistence;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
|
2024-04-08 11:17:32 +02:00
|
|
|
using Umbraco.Cms.Infrastructure.Services;
|
2021-03-08 17:13:37 +01:00
|
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
|
|
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
2022-04-26 10:22:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[TestFixture]
|
|
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
|
|
|
|
public class CacheInstructionServiceTests : UmbracoIntegrationTest
|
2021-03-08 17:13:37 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
private const string LocalIdentity = "localIdentity";
|
|
|
|
|
private const string AlternateIdentity = "alternateIdentity";
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
private CancellationToken CancellationToken => new();
|
|
|
|
|
private CacheRefresherCollection CacheRefreshers => GetRequiredService<CacheRefresherCollection>();
|
|
|
|
|
private IServerRoleAccessor ServerRoleAccessor => GetRequiredService<IServerRoleAccessor>();
|
Examine 2.0 integration (#10241)
* Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't
* Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues.
* Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager
* fix up issues with rebuilding and management dashboard.
* removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state.
* Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom
* lazily acquire application id (fix unit tests)
* Fixes resource casing and missing test file
* Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service.
* For UmbracoTestServerTestBase enable nucache services
* Fixing tests
* Fix another test
* Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref.
* Fixes up some review notes
* Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it
* Checks for parseexception when executing the query
* Use application root instead of duplicating functionality.
* Added Examine project to netcore only solution file
* Fixed casing issue with LazyLoad, that is not lowercase.
* uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type
* Fix tests
* remove legacy test project from solution file
* Fix test
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 18:31:38 +10:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Confirms_Cold_Boot_Required_When_Instructions_Exist_And_None_Have_Been_Synced()
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var instructions = CreateInstructions();
|
|
|
|
|
sut.DeliverInstructions(instructions, LocalIdentity);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var result = sut.IsColdBootRequired(0);
|
2021-03-09 18:00:31 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.IsTrue(result);
|
|
|
|
|
}
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Confirms_Cold_Boot_Required_When_Last_Synced_Instruction_Not_Found()
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
2021-03-08 17:39:41 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var instructions = CreateInstructions();
|
|
|
|
|
sut.DeliverInstructions(instructions, LocalIdentity); // will create with Id = 1
|
2021-03-09 18:00:31 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var result = sut.IsColdBootRequired(2);
|
2021-03-08 17:39:41 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.IsTrue(result);
|
|
|
|
|
}
|
2021-03-08 17:39:41 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Confirms_Cold_Boot_Not_Required_When_Last_Synced_Instruction_Found()
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var instructions = CreateInstructions();
|
|
|
|
|
sut.DeliverInstructions(instructions, LocalIdentity); // will create with Id = 1
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var result = sut.IsColdBootRequired(1);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.IsFalse(result);
|
|
|
|
|
}
|
2021-03-09 18:00:31 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[TestCase(1, 10, false, 4)]
|
|
|
|
|
[TestCase(1, 3, true, 4)]
|
|
|
|
|
public void Confirms_Instruction_Count_Over_Limit(int lastId, int limit, bool expectedResult, int expectedCount)
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
2021-03-09 18:00:31 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
CreateAndDeliveryMultipleInstructions(sut); // 3 records, each with 2 instructions = 6.
|
2021-03-09 18:00:31 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var result = sut.IsInstructionCountOverLimit(lastId, limit, out var count);
|
2021-03-09 18:00:31 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(expectedResult, result);
|
|
|
|
|
Assert.AreEqual(expectedCount, count);
|
|
|
|
|
}
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Get_Max_Instruction_Id()
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
CreateAndDeliveryMultipleInstructions(sut);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var result = sut.GetMaxInstructionId();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(3, result);
|
|
|
|
|
}
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Deliver_Instructions()
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var instructions = CreateInstructions();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
sut.DeliverInstructions(instructions, LocalIdentity);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
AssertDeliveredInstructions();
|
|
|
|
|
}
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Deliver_Instructions_In_Batches()
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var instructions = CreateInstructions();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
sut.DeliverInstructionsInBatches(instructions, LocalIdentity);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
AssertDeliveredInstructions();
|
|
|
|
|
}
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
private List<RefreshInstruction> CreateInstructions() => new()
|
|
|
|
|
{
|
|
|
|
|
new(UserCacheRefresher.UniqueId, RefreshMethodType.RefreshByIds, Guid.Empty, 0, "[-1]", null),
|
|
|
|
|
new(UserCacheRefresher.UniqueId, RefreshMethodType.RefreshByIds, Guid.Empty, 0, "[-1]", null)
|
|
|
|
|
};
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
private void AssertDeliveredInstructions()
|
|
|
|
|
{
|
|
|
|
|
List<CacheInstructionDto> cacheInstructions;
|
|
|
|
|
var sqlContext = GetRequiredService<ISqlContext>();
|
|
|
|
|
var sql = sqlContext.Sql()
|
|
|
|
|
.Select<CacheInstructionDto>()
|
|
|
|
|
.From<CacheInstructionDto>();
|
|
|
|
|
using (var scope = ScopeProvider.CreateScope())
|
2021-03-08 17:13:37 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
cacheInstructions = ScopeAccessor.AmbientScope.Database.Fetch<CacheInstructionDto>(sql);
|
|
|
|
|
scope.Complete();
|
2021-03-08 17:13:37 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.Multiple(() =>
|
2021-03-08 17:13:37 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(1, cacheInstructions.Count);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var firstInstruction = cacheInstructions.First();
|
|
|
|
|
Assert.AreEqual(2, firstInstruction.InstructionCount);
|
|
|
|
|
Assert.AreEqual(LocalIdentity, firstInstruction.OriginIdentity);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Can_Process_Instructions()
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// Create three instruction records, each with two instructions. First two records are for a different identity.
|
|
|
|
|
CreateAndDeliveryMultipleInstructions(sut);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var result = sut.ProcessInstructions(CacheRefreshers, ServerRoleAccessor.CurrentServerRole, CancellationToken,
|
|
|
|
|
LocalIdentity, DateTime.UtcNow.AddSeconds(-1), -1);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.Multiple(() =>
|
2021-03-08 17:13:37 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(3, result.LastId); // 3 records found.
|
|
|
|
|
Assert.AreEqual(2,
|
|
|
|
|
result.NumberOfInstructionsProcessed); // 2 records processed (as one is for the same identity).
|
|
|
|
|
Assert.IsFalse(result.InstructionsWerePruned);
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Can_Process_And_Purge_Instructions()
|
|
|
|
|
{
|
|
|
|
|
// Purging of instructions only occurs on single or master servers, so we need to ensure this is set before running the test.
|
|
|
|
|
EnsureServerRegistered();
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
CreateAndDeliveryMultipleInstructions(sut);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var result = sut.ProcessInstructions(CacheRefreshers, ServerRoleAccessor.CurrentServerRole, CancellationToken,
|
|
|
|
|
LocalIdentity, DateTime.UtcNow.AddHours(-1), -1);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.IsTrue(result.InstructionsWerePruned);
|
|
|
|
|
}
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Processes_No_Instructions_When_CancellationToken_is_Cancelled()
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
CreateAndDeliveryMultipleInstructions(sut);
|
Examine 2.0 integration (#10241)
* Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't
* Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues.
* Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager
* fix up issues with rebuilding and management dashboard.
* removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state.
* Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom
* lazily acquire application id (fix unit tests)
* Fixes resource casing and missing test file
* Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service.
* For UmbracoTestServerTestBase enable nucache services
* Fixing tests
* Fix another test
* Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref.
* Fixes up some review notes
* Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it
* Checks for parseexception when executing the query
* Use application root instead of duplicating functionality.
* Added Examine project to netcore only solution file
* Fixed casing issue with LazyLoad, that is not lowercase.
* uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type
* Fix tests
* remove legacy test project from solution file
* Fix test
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 18:31:38 +10:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
|
cancellationTokenSource.Cancel();
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var result = sut.ProcessInstructions(CacheRefreshers, ServerRoleAccessor.CurrentServerRole,
|
|
|
|
|
cancellationTokenSource.Token, LocalIdentity, DateTime.UtcNow.AddSeconds(-1), -1);
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.Multiple(() =>
|
2021-04-12 13:27:25 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(0, result.LastId);
|
|
|
|
|
Assert.AreEqual(0, result.NumberOfInstructionsProcessed);
|
|
|
|
|
Assert.IsFalse(result.InstructionsWerePruned);
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Processes_Instructions_Only_Once()
|
|
|
|
|
{
|
|
|
|
|
// This test shows what's happening in issue #10112
|
|
|
|
|
// The DatabaseServerMessenger will run its sync operation every five seconds which calls CacheInstructionService.ProcessInstructions,
|
|
|
|
|
// which is why the CacheRefresherNotification keeps dispatching, because the cache instructions gets constantly processed.
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
|
|
|
|
CreateAndDeliveryMultipleInstructions(sut);
|
|
|
|
|
|
|
|
|
|
var lastId = -1;
|
|
|
|
|
// Run once
|
|
|
|
|
var result = sut.ProcessInstructions(CacheRefreshers, ServerRoleAccessor.CurrentServerRole, CancellationToken,
|
|
|
|
|
LocalIdentity, DateTime.UtcNow.AddSeconds(-1), lastId);
|
|
|
|
|
|
|
|
|
|
Assert.Multiple(() =>
|
2021-04-12 13:27:25 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(3, result.LastId); // 3 records found.
|
Resolved more warnings, and marked more warning types as errors (#16991)
* Fix warnings SA1111, SA1028, SA1500, IDE1270 in Umbraco.Web.Website, and updated rules.
* Remove warnings: IDE0270: Null check can be simplified
* More SqlServer project warnings resolved
* CS0105 namespace appeared already
* Suppress warning until implementation:
#pragma warning disable CS0162 // Unreachable code detected
#pragma warning disable CS0618 // Type or member is obsolete
CS0162 remove unreachable code
SA1028 remove trailing whitespace
SA1106 no empty statements
CS1570 malformed XML
CS1572 corrected xml parameter
CS1573 param tag added
IDE0007 var not explicit
IDE0008 explicit not var
IDE0057 simplify substring
IDE0074 compound assignment
CA1825 array.empty
Down to 3479 warnings
* - SA1116, SA117 params on same line
- IDE0057 substring simplified
Specific warnings for Umbraco.Tests.Benchmarks
* Fixed IDE0074 compound assignment and added specific warnings for Umbraco.Tests.Common
* Specific warnings for Umbraco.Tests.Integration and Umbraco.Tests.Common
Fixed:
- SA1111, SA1116, SA117 params and line formatting (not all as there are many)
- SA1122 string.Empty
- IDE0057 simplify substring
- IDE0044,IDE0044 make field readonly
- IDE1006 naming rule violation (add _)
- SA1111 closing parenthesis on line of last parameter
- SA1649 filename match type name
- SA1312,SA1306 lowercase variable and field names
* Fixed various warnings where they are more straight-forward, including:
- SA1649 file name match type name
- SA111 parenthesis on line of last parameter
- IDE0028 simplify collection initializer
- SA1306 lower-case letter field
- IDE044 readonly field
- SA1122 string.Empty
- SA1116 params same line
- IDE1006 upper casing
- IDE0041 simplify null check
Updated the following projects to only list their remaining specific warning codes:
- Umbraco.Tests.UnitTests
Typo in `Umbraco.Web.Website` project
* Reverted test change
* Now 1556 warnings.
Fixed various warnings where they are more straight-forward, including:
- SA1111/SA1116/SA1119 parenthesis
- SA1117 params
- SA1312 lowercase variable
- SA1121 built-in type
- SA1500/SA1513/SA1503 formatting braces
- SA1400 declare access modifier
- SA1122 string.Empty
- SA1310 no underscore
- IDE0049 name simplified
- IDE0057 simplify substring
- IDE0074 compound assignment
- IDE0032 use auto-property
- IDE0037 simplify member name
- IDE0008 explicit type not var
- IDE0016/IDE0270/IDE0041 simplify null checks
- IDE0048/SA1407 clarity in arithmetic
- IDE1006 correct param names
- IDE0042 deconstruct variable
- IDE0044 readonly
- IDE0018 inline variable declarations
- IDE0074/IDE0054 compound assignment
- IDE1006 naming
- CS1573 param XML
- CS0168 unused variable
Comment formatting in project files for consistency.
Updated all projects to only list remaining specific warning codes as warnings instead of errors (errors is now default).
* Type not var, and more warning exceptions
* Tweaked merge issue, readded comment about rollback
* Readded comment re rollback.
* Readded comments
* Comment tweak
* Comment tweak
2024-09-24 12:56:28 +01:00
|
|
|
Assert.AreEqual(2, result.NumberOfInstructionsProcessed); // 2 records processed (as one is for the same identity).
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.IsFalse(result.InstructionsWerePruned);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// DatabaseServerMessenger stores the LastID after ProcessInstructions has been run.
|
|
|
|
|
lastId = result.LastId;
|
|
|
|
|
|
|
|
|
|
// The instructions has now been processed and shouldn't be processed on the next call...
|
|
|
|
|
// Run again.
|
Resolved more warnings, and marked more warning types as errors (#16991)
* Fix warnings SA1111, SA1028, SA1500, IDE1270 in Umbraco.Web.Website, and updated rules.
* Remove warnings: IDE0270: Null check can be simplified
* More SqlServer project warnings resolved
* CS0105 namespace appeared already
* Suppress warning until implementation:
#pragma warning disable CS0162 // Unreachable code detected
#pragma warning disable CS0618 // Type or member is obsolete
CS0162 remove unreachable code
SA1028 remove trailing whitespace
SA1106 no empty statements
CS1570 malformed XML
CS1572 corrected xml parameter
CS1573 param tag added
IDE0007 var not explicit
IDE0008 explicit not var
IDE0057 simplify substring
IDE0074 compound assignment
CA1825 array.empty
Down to 3479 warnings
* - SA1116, SA117 params on same line
- IDE0057 substring simplified
Specific warnings for Umbraco.Tests.Benchmarks
* Fixed IDE0074 compound assignment and added specific warnings for Umbraco.Tests.Common
* Specific warnings for Umbraco.Tests.Integration and Umbraco.Tests.Common
Fixed:
- SA1111, SA1116, SA117 params and line formatting (not all as there are many)
- SA1122 string.Empty
- IDE0057 simplify substring
- IDE0044,IDE0044 make field readonly
- IDE1006 naming rule violation (add _)
- SA1111 closing parenthesis on line of last parameter
- SA1649 filename match type name
- SA1312,SA1306 lowercase variable and field names
* Fixed various warnings where they are more straight-forward, including:
- SA1649 file name match type name
- SA111 parenthesis on line of last parameter
- IDE0028 simplify collection initializer
- SA1306 lower-case letter field
- IDE044 readonly field
- SA1122 string.Empty
- SA1116 params same line
- IDE1006 upper casing
- IDE0041 simplify null check
Updated the following projects to only list their remaining specific warning codes:
- Umbraco.Tests.UnitTests
Typo in `Umbraco.Web.Website` project
* Reverted test change
* Now 1556 warnings.
Fixed various warnings where they are more straight-forward, including:
- SA1111/SA1116/SA1119 parenthesis
- SA1117 params
- SA1312 lowercase variable
- SA1121 built-in type
- SA1500/SA1513/SA1503 formatting braces
- SA1400 declare access modifier
- SA1122 string.Empty
- SA1310 no underscore
- IDE0049 name simplified
- IDE0057 simplify substring
- IDE0074 compound assignment
- IDE0032 use auto-property
- IDE0037 simplify member name
- IDE0008 explicit type not var
- IDE0016/IDE0270/IDE0041 simplify null checks
- IDE0048/SA1407 clarity in arithmetic
- IDE1006 correct param names
- IDE0042 deconstruct variable
- IDE0044 readonly
- IDE0018 inline variable declarations
- IDE0074/IDE0054 compound assignment
- IDE1006 naming
- CS1573 param XML
- CS0168 unused variable
Comment formatting in project files for consistency.
Updated all projects to only list remaining specific warning codes as warnings instead of errors (errors is now default).
* Type not var, and more warning exceptions
* Tweaked merge issue, readded comment about rollback
* Readded comment re rollback.
* Readded comments
* Comment tweak
* Comment tweak
2024-09-24 12:56:28 +01:00
|
|
|
var secondResult = sut.ProcessInstructions(
|
|
|
|
|
CacheRefreshers,
|
|
|
|
|
ServerRoleAccessor.CurrentServerRole,
|
|
|
|
|
CancellationToken,
|
|
|
|
|
LocalIdentity,
|
|
|
|
|
DateTime.UtcNow.AddSeconds(-1),
|
|
|
|
|
lastId);
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
Resolved more warnings, and marked more warning types as errors (#16991)
* Fix warnings SA1111, SA1028, SA1500, IDE1270 in Umbraco.Web.Website, and updated rules.
* Remove warnings: IDE0270: Null check can be simplified
* More SqlServer project warnings resolved
* CS0105 namespace appeared already
* Suppress warning until implementation:
#pragma warning disable CS0162 // Unreachable code detected
#pragma warning disable CS0618 // Type or member is obsolete
CS0162 remove unreachable code
SA1028 remove trailing whitespace
SA1106 no empty statements
CS1570 malformed XML
CS1572 corrected xml parameter
CS1573 param tag added
IDE0007 var not explicit
IDE0008 explicit not var
IDE0057 simplify substring
IDE0074 compound assignment
CA1825 array.empty
Down to 3479 warnings
* - SA1116, SA117 params on same line
- IDE0057 substring simplified
Specific warnings for Umbraco.Tests.Benchmarks
* Fixed IDE0074 compound assignment and added specific warnings for Umbraco.Tests.Common
* Specific warnings for Umbraco.Tests.Integration and Umbraco.Tests.Common
Fixed:
- SA1111, SA1116, SA117 params and line formatting (not all as there are many)
- SA1122 string.Empty
- IDE0057 simplify substring
- IDE0044,IDE0044 make field readonly
- IDE1006 naming rule violation (add _)
- SA1111 closing parenthesis on line of last parameter
- SA1649 filename match type name
- SA1312,SA1306 lowercase variable and field names
* Fixed various warnings where they are more straight-forward, including:
- SA1649 file name match type name
- SA111 parenthesis on line of last parameter
- IDE0028 simplify collection initializer
- SA1306 lower-case letter field
- IDE044 readonly field
- SA1122 string.Empty
- SA1116 params same line
- IDE1006 upper casing
- IDE0041 simplify null check
Updated the following projects to only list their remaining specific warning codes:
- Umbraco.Tests.UnitTests
Typo in `Umbraco.Web.Website` project
* Reverted test change
* Now 1556 warnings.
Fixed various warnings where they are more straight-forward, including:
- SA1111/SA1116/SA1119 parenthesis
- SA1117 params
- SA1312 lowercase variable
- SA1121 built-in type
- SA1500/SA1513/SA1503 formatting braces
- SA1400 declare access modifier
- SA1122 string.Empty
- SA1310 no underscore
- IDE0049 name simplified
- IDE0057 simplify substring
- IDE0074 compound assignment
- IDE0032 use auto-property
- IDE0037 simplify member name
- IDE0008 explicit type not var
- IDE0016/IDE0270/IDE0041 simplify null checks
- IDE0048/SA1407 clarity in arithmetic
- IDE1006 correct param names
- IDE0042 deconstruct variable
- IDE0044 readonly
- IDE0018 inline variable declarations
- IDE0074/IDE0054 compound assignment
- IDE1006 naming
- CS1573 param XML
- CS0168 unused variable
Comment formatting in project files for consistency.
Updated all projects to only list remaining specific warning codes as warnings instead of errors (errors is now default).
* Type not var, and more warning exceptions
* Tweaked merge issue, readded comment about rollback
* Readded comment re rollback.
* Readded comments
* Comment tweak
* Comment tweak
2024-09-24 12:56:28 +01:00
|
|
|
Assert.AreEqual(
|
|
|
|
|
0,
|
2022-06-21 08:09:38 +02:00
|
|
|
secondResult
|
|
|
|
|
.LastId); // No instructions was processed so LastId is 0, this is consistent with behavior from V8
|
|
|
|
|
Assert.AreEqual(0, secondResult.NumberOfInstructionsProcessed); // Nothing was processed.
|
|
|
|
|
Assert.IsFalse(secondResult.InstructionsWerePruned);
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Processes_New_Instructions()
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
|
|
|
|
CreateAndDeliveryMultipleInstructions(sut);
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var lastId = -1;
|
|
|
|
|
var result = sut.ProcessInstructions(CacheRefreshers, ServerRoleAccessor.CurrentServerRole, CancellationToken,
|
|
|
|
|
LocalIdentity, DateTime.UtcNow.AddSeconds(-1), lastId);
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(3, result.LastId); // Make sure LastId is 3, the rest is tested in other test.
|
|
|
|
|
lastId = result.LastId;
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// Add new instruction
|
|
|
|
|
var instructions = CreateInstructions();
|
|
|
|
|
sut.DeliverInstructions(instructions, AlternateIdentity);
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var secondResult = sut.ProcessInstructions(CacheRefreshers, ServerRoleAccessor.CurrentServerRole,
|
|
|
|
|
CancellationToken, LocalIdentity, DateTime.UtcNow.AddSeconds(-1), lastId);
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.Multiple(() =>
|
2021-04-12 13:27:25 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(4, secondResult.LastId);
|
|
|
|
|
Assert.AreEqual(1, secondResult.NumberOfInstructionsProcessed);
|
|
|
|
|
Assert.IsFalse(secondResult.InstructionsWerePruned);
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Correct_ID_For_Instruction_With_Same_Identity()
|
|
|
|
|
{
|
|
|
|
|
var sut = (CacheInstructionService)GetRequiredService<ICacheInstructionService>();
|
|
|
|
|
CreateAndDeliveryMultipleInstructions(sut);
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var lastId = -1;
|
|
|
|
|
var result = sut.ProcessInstructions(CacheRefreshers, ServerRoleAccessor.CurrentServerRole, CancellationToken,
|
|
|
|
|
LocalIdentity, DateTime.UtcNow.AddSeconds(-1), lastId);
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(3, result.LastId); // Make sure LastId is 3, the rest is tested in other test.
|
|
|
|
|
lastId = result.LastId;
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// Add new instruction
|
|
|
|
|
var instructions = CreateInstructions();
|
|
|
|
|
sut.DeliverInstructions(instructions, LocalIdentity);
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
var secondResult = sut.ProcessInstructions(CacheRefreshers, ServerRoleAccessor.CurrentServerRole,
|
|
|
|
|
CancellationToken, LocalIdentity, DateTime.UtcNow.AddSeconds(-1), lastId);
|
2021-04-12 13:27:25 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.Multiple(() =>
|
2021-03-08 17:13:37 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
Assert.AreEqual(4, secondResult.LastId);
|
|
|
|
|
Assert.AreEqual(0, secondResult.NumberOfInstructionsProcessed);
|
|
|
|
|
Assert.IsFalse(secondResult.InstructionsWerePruned);
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-08 17:13:37 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
private void CreateAndDeliveryMultipleInstructions(CacheInstructionService sut)
|
|
|
|
|
{
|
|
|
|
|
for (var i = 0; i < 3; i++)
|
2021-03-08 17:13:37 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
var instructions = CreateInstructions();
|
|
|
|
|
sut.DeliverInstructions(instructions, i == 2 ? LocalIdentity : AlternateIdentity);
|
2021-03-08 17:13:37 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
|
|
|
|
|
private void EnsureServerRegistered()
|
|
|
|
|
{
|
|
|
|
|
var serverRegistrationService = GetRequiredService<IServerRegistrationService>();
|
|
|
|
|
serverRegistrationService.TouchServer("http://localhost", TimeSpan.FromMinutes(10));
|
|
|
|
|
}
|
2021-03-08 17:13:37 +01:00
|
|
|
}
|