зеркало из https://github.com/dotnet/orleans.git
Fix regression in `CollectionAgeLimitAttribute` (#8681)
* Fix regression in CollectionAgeLimitAttribute * Prevent setting values less than MinAgeLimit * Reduce the tomfoolery in EchoTaskGrainTests
This commit is contained in:
Родитель
0c0ae12d78
Коммит
b23e3d8785
|
@ -35,22 +35,22 @@ namespace Orleans
|
|||
/// <summary>
|
||||
/// Gets or sets the number of days to delay collecting an idle activation for.
|
||||
/// </summary>
|
||||
public double Days { private get; init; }
|
||||
public double Days { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of hours to delay collecting an idle activation for.
|
||||
/// </summary>
|
||||
public double Hours { private get; init; }
|
||||
public double Hours { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of minutes to delay collecting an idle activation for.
|
||||
/// </summary>
|
||||
public double Minutes { private get; init; }
|
||||
public double Minutes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this grain should never be collected by the idle activation collector.
|
||||
/// </summary>
|
||||
public bool AlwaysActive { private get; init; }
|
||||
public bool AlwaysActive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the idle activation collection age.
|
||||
|
@ -79,7 +79,7 @@ namespace Orleans
|
|||
var span = AlwaysActive
|
||||
? TimeSpan.FromDays(short.MaxValue)
|
||||
: TimeSpan.FromDays(Days) + TimeSpan.FromHours(Hours) + TimeSpan.FromMinutes(Minutes);
|
||||
return span <= TimeSpan.Zero
|
||||
return span < MinAgeLimit
|
||||
? MinAgeLimit
|
||||
: span;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ namespace DefaultCluster.Tests.General
|
|||
private readonly TimeSpan timeout = Debugger.IsAttached ? TimeSpan.FromMinutes(10) : TimeSpan.FromSeconds(10);
|
||||
private const string expectedEcho = "Hello from EchoGrain";
|
||||
private const string expectedEchoError = "Error from EchoGrain";
|
||||
private IEchoTaskGrain grain;
|
||||
|
||||
public static readonly TimeSpan Epsilon = TimeSpan.FromSeconds(1);
|
||||
|
||||
|
@ -30,7 +29,7 @@ namespace DefaultCluster.Tests.General
|
|||
[Fact, TestCategory("BVT"), TestCategory("Echo")]
|
||||
public void EchoGrain_GetGrain()
|
||||
{
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
_ = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
}
|
||||
|
||||
[Fact, TestCategory("BVT"), TestCategory("Echo")]
|
||||
|
@ -39,7 +38,7 @@ namespace DefaultCluster.Tests.General
|
|||
Stopwatch clock = new Stopwatch();
|
||||
|
||||
clock.Start();
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
this.Logger.LogInformation("CreateGrain took {Elapsed}", clock.Elapsed);
|
||||
|
||||
clock.Restart();
|
||||
|
@ -52,7 +51,7 @@ namespace DefaultCluster.Tests.General
|
|||
[Fact, TestCategory("BVT"), TestCategory("Echo")]
|
||||
public async Task EchoGrain_EchoError()
|
||||
{
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
|
||||
Task<string> promise = grain.EchoErrorAsync(expectedEchoError);
|
||||
await promise.ContinueWith(t =>
|
||||
|
@ -69,7 +68,7 @@ namespace DefaultCluster.Tests.General
|
|||
[Fact, TestCategory("SlowBVT"), TestCategory("Echo"), TestCategory("Timeout")]
|
||||
public async Task EchoGrain_Timeout_ContinueWith()
|
||||
{
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
|
||||
TimeSpan delay5 = TimeSpan.FromSeconds(30); // grain call timeout (set in config)
|
||||
TimeSpan delay45 = TimeSpan.FromSeconds(45);
|
||||
|
@ -94,7 +93,7 @@ namespace DefaultCluster.Tests.General
|
|||
[Fact, TestCategory("SlowBVT"), TestCategory("Echo")]
|
||||
public async Task EchoGrain_Timeout_Await()
|
||||
{
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
|
||||
TimeSpan delay5 = TimeSpan.FromSeconds(5);
|
||||
TimeSpan delay25 = TimeSpan.FromSeconds(25);
|
||||
|
@ -118,7 +117,7 @@ namespace DefaultCluster.Tests.General
|
|||
[Fact, TestCategory("SlowBVT"), TestCategory("Echo"), TestCategory("Timeout")]
|
||||
public void EchoGrain_Timeout_Result()
|
||||
{
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
|
||||
TimeSpan delay5 = TimeSpan.FromSeconds(5);
|
||||
TimeSpan delay25 = TimeSpan.FromSeconds(25);
|
||||
|
@ -145,15 +144,33 @@ namespace DefaultCluster.Tests.General
|
|||
{
|
||||
Stopwatch clock = new Stopwatch();
|
||||
|
||||
await EchoGrain_Echo();
|
||||
clock.Start();
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
this.Logger.LogInformation("CreateGrain took {Elapsed}", clock.Elapsed);
|
||||
|
||||
clock.Restart();
|
||||
string received = await grain.EchoAsync(expectedEcho);
|
||||
this.Logger.LogInformation("EchoGrain.Echo took {Elapsed}", clock.Elapsed);
|
||||
|
||||
Assert.Equal(expectedEcho, received);
|
||||
|
||||
clock.Start();
|
||||
string received = await grain.GetLastEchoAsync();
|
||||
|
||||
received = await grain.GetLastEchoAsync();
|
||||
this.Logger.LogInformation("EchoGrain.LastEcho took {Elapsed}", clock.Elapsed);
|
||||
|
||||
Assert.Equal(expectedEcho, received); // LastEcho-Echo
|
||||
|
||||
await EchoGrain_EchoError();
|
||||
Task<string> promise = grain.EchoErrorAsync(expectedEchoError);
|
||||
await promise.ContinueWith(t =>
|
||||
{
|
||||
if (!t.IsFaulted) Assert.True(false); // EchoError should not have completed successfully
|
||||
|
||||
Exception exc = t.Exception;
|
||||
while (exc is AggregateException) exc = exc.InnerException;
|
||||
string received = exc.Message;
|
||||
Assert.Equal(expectedEchoError, received);
|
||||
}).WithTimeout(timeout);
|
||||
|
||||
clock.Restart();
|
||||
received = await grain.GetLastEchoAsync();
|
||||
|
@ -169,7 +186,7 @@ namespace DefaultCluster.Tests.General
|
|||
|
||||
string what = "CreateGrain";
|
||||
clock.Start();
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
this.Logger.LogInformation("{What} took {Elapsed}", what, clock.Elapsed);
|
||||
|
||||
what = "EchoGrain.Ping";
|
||||
|
@ -186,7 +203,7 @@ namespace DefaultCluster.Tests.General
|
|||
|
||||
string what = "CreateGrain";
|
||||
clock.Start();
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
this.Logger.LogInformation("{What} took {Elapsed}", what, clock.Elapsed);
|
||||
|
||||
what = "EchoGrain.PingLocalSilo";
|
||||
|
@ -202,7 +219,7 @@ namespace DefaultCluster.Tests.General
|
|||
|
||||
string what = "CreateGrain";
|
||||
clock.Start();
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
this.Logger.LogInformation("{What} took {Elapsed}", what, clock.Elapsed);
|
||||
|
||||
SiloAddress silo1 = HostedCluster.Primary.SiloAddress;
|
||||
|
@ -226,7 +243,7 @@ namespace DefaultCluster.Tests.General
|
|||
|
||||
string what = "CreateGrain";
|
||||
clock.Start();
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
this.Logger.LogInformation("{What} took {Elapsed}", what, clock.Elapsed);
|
||||
|
||||
what = "EchoGrain.PingOtherSilo";
|
||||
|
@ -242,7 +259,7 @@ namespace DefaultCluster.Tests.General
|
|||
|
||||
string what = "CreateGrain";
|
||||
clock.Start();
|
||||
grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
var grain = this.GrainFactory.GetGrain<IEchoTaskGrain>(Guid.NewGuid());
|
||||
this.Logger.LogInformation("{What} took {Elapsed}", what, clock.Elapsed);
|
||||
|
||||
what = "EchoGrain.PingOtherSiloMembership";
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace UnitTests.Grains
|
|||
}
|
||||
|
||||
[StorageProvider(ProviderName = "MemoryStore")]
|
||||
[CollectionAgeLimit(Days = 1)] // Added to test the attribute itself.
|
||||
public class EchoGrain : Grain<EchoTaskGrainState>, IEchoGrain
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
|
@ -58,6 +59,7 @@ namespace UnitTests.Grains
|
|||
}
|
||||
|
||||
[StorageProvider(ProviderName = "MemoryStore")]
|
||||
[CollectionAgeLimit("01:00:00")] // Added to test the attribute itself.
|
||||
internal class EchoTaskGrain : Grain<EchoTaskGrainState>, IEchoTaskGrain, IDebuggerHelperTestGrain
|
||||
{
|
||||
private readonly IInternalGrainFactory internalGrainFactory;
|
||||
|
|
Загрузка…
Ссылка в новой задаче