Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression in CollectionAgeLimitAttribute #8681

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Orleans.Core/Configuration/CollectionAgeLimitAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ public CollectionAgeLimitAttribute() { }
/// <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.
Expand Down Expand Up @@ -79,7 +79,7 @@ private TimeSpan CalculateValue()
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;
}
Expand Down
47 changes: 32 additions & 15 deletions test/DefaultCluster.Tests/EchoTaskGrainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class EchoTaskGrainTests : HostedTestClusterEnsureDefaultStarted
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);

Expand All @@ -30,7 +29,7 @@ public EchoTaskGrainTests(DefaultClusterFixture fixture)
[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")]
Expand All @@ -39,7 +38,7 @@ public async Task EchoGrain_Echo()
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();
Expand All @@ -52,7 +51,7 @@ public async Task EchoGrain_Echo()
[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 =>
Expand All @@ -69,7 +68,7 @@ await promise.ContinueWith(t =>
[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);
Expand All @@ -94,7 +93,7 @@ await promise.ContinueWith(
[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);
Expand All @@ -118,7 +117,7 @@ public async Task EchoGrain_Timeout_Await()
[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);
Expand All @@ -145,15 +144,33 @@ public async Task EchoGrain_LastEcho()
{
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();
Expand All @@ -169,7 +186,7 @@ public async Task EchoGrain_Ping()

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";
Expand All @@ -186,7 +203,7 @@ public async Task EchoGrain_PingSilo_Local()

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";
Expand All @@ -202,7 +219,7 @@ public async Task EchoGrain_PingSilo_Remote()

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;
Expand All @@ -226,7 +243,7 @@ public async Task EchoGrain_PingSilo_OtherSilo()

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";
Expand All @@ -242,7 +259,7 @@ public async Task EchoGrain_PingSilo_OtherSilo_Membership()

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";
Expand Down
2 changes: 2 additions & 0 deletions test/Grains/TestInternalGrains/EchoTaskGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class EchoTaskGrainState
}

[StorageProvider(ProviderName = "MemoryStore")]
[CollectionAgeLimit(Days = 1)] // Added to test the attribute itself.
public class EchoGrain : Grain<EchoTaskGrainState>, IEchoGrain
{
private readonly ILogger logger;
Expand Down Expand Up @@ -58,6 +59,7 @@ public Task<string> EchoError(string data)
}

[StorageProvider(ProviderName = "MemoryStore")]
[CollectionAgeLimit("01:00:00")] // Added to test the attribute itself.
internal class EchoTaskGrain : Grain<EchoTaskGrainState>, IEchoTaskGrain, IDebuggerHelperTestGrain
{
private readonly IInternalGrainFactory internalGrainFactory;
Expand Down