Fix flaky OneWay_Deactivation_CacheInvalidated test (#8721)

This commit is contained in:
Reuben Bond 2023-11-11 13:14:22 -08:00 коммит произвёл GitHub
Родитель e94f117e72
Коммит b352f06677
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 7 добавлений и 12 удалений

Просмотреть файл

@ -1,7 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using Orleans.Configuration;
using Orleans.Configuration.Internal;
using Orleans.Runtime;
using Orleans.Runtime.GrainDirectory;
using Orleans.Runtime.Placement;
using Orleans.TestingHost;
using TestExtensions;
using UnitTests.GrainInterfaces;
@ -53,6 +55,7 @@ namespace UnitTests.General
IOneWayGrain grainToCallFrom;
while (true)
{
RequestContext.Set(IPlacementDirector.PlacementHintKey, _fixture.HostedCluster.Primary.SiloAddress);
grainToCallFrom = _fixture.Client.GetGrain<IOneWayGrain>(Guid.NewGuid());
var grainHost = await grainToCallFrom.GetSiloAddress();
if (grainHost.Equals(_fixture.HostedCluster.Primary.SiloAddress))
@ -62,6 +65,7 @@ namespace UnitTests.General
}
// Activate the grain & record its address.
RequestContext.Remove(IPlacementDirector.PlacementHintKey);
var grainToDeactivate = await grainToCallFrom.GetOtherGrain();
var initialActivationId = await grainToDeactivate.GetActivationId();
var grainId = grainToDeactivate.GetGrainId();
@ -75,23 +79,14 @@ namespace UnitTests.General
Assert.Equal(1, count);
Assert.NotEqual(initialActivationId, finalActivationId);
// Test that cache was invalidated, but only if the ActivationAddress has changed.
// Test that cache was updated.
// We don't know what the whole activation address should be, but we do know
// that some entry should be successfully removed for the provided grain id.
// that some entry should be successfully updated for the provided grain id.
var newActivationAddress = directoryCache.Operations
.OfType<TestDirectoryCache.CacheOperation.AddOrUpdate>()
.Last(op => op.Value.GrainId.Equals(grainId))
.Value;
var invalidationOp = directoryCache.Operations
.OfType<TestDirectoryCache.CacheOperation.RemoveActivation>()
.FirstOrDefault(op => op.Key.Equals(activationAddress) && op.Result);
if (!newActivationAddress.Equals(activationAddress) && invalidationOp is null)
{
var ops = string.Join(", ", directoryCache.Operations.Select(op => op.ToString()));
Assert.True(invalidationOp is not null, $"Should have processed a cache invalidation for the target activation {activationAddress}. Cache ops: {ops}");
}
Assert.NotNull(newActivationAddress);
directoryCache.Operations.Clear();
}