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

correct the double call to OnActivateAsync on IRemindable grains #165

Merged
merged 1 commit into from
Aug 1, 2024
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
4 changes: 0 additions & 4 deletions src/OrleansTestKit/TestKitSilo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,11 @@ public async Task<T> CreateGrainAsync<T>(IdSpan identity, CancellationToken canc
// Used to enable reminder context on during activate
using var reminderContext =
await GetReminderActivationContext(grain, cancellation).ConfigureAwait(false);

await grain.OnActivateAsync(cancellation).ConfigureAwait(false);
_activatedGrains.Add(grain);
}

await grain.OnActivateAsync(cancellation).ConfigureAwait(false);
_activatedGrains.Add(grain);


return (T)grain;
}
}
38 changes: 38 additions & 0 deletions test/OrleansTestKit.Tests/Grains/ActivationCountWithReminder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Orleans.Runtime;
using Orleans.Streams;

namespace TestGrains;

public sealed class ActivationCountWithReminder : Grain, IGrainWithIntegerKey, IRemindable
{
private int _activationCount;

public override Task OnActivateAsync(CancellationToken cancellationToken)
{
_activationCount++;
return base.OnActivateAsync(cancellationToken);
}

public Task<int> GetActivationCount() => Task.FromResult(_activationCount);


Task IRemindable.ReceiveReminder(string reminderName, TickStatus status)
{
return Task.CompletedTask;
}

public Task RegisterReminder(string reminderName, TimeSpan dueTime, TimeSpan period)
{
return this.RegisterOrUpdateReminder(reminderName, dueTime, period);
}

public async Task UnregisterReminder(string reminderName)
{
var reminder = await this.GetReminder(reminderName);

if (reminder != null)
{
await this.UnregisterReminder(reminder);
}
}
}
12 changes: 12 additions & 0 deletions test/OrleansTestKit.Tests/Tests/ActivationGrainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,16 @@ public async Task ShouldThrowNotSupportedException()
await Assert.ThrowsAsync<NotSupportedException>(
async () => await Silo.CreateGrainAsync<StatefulUnsupportedActivationGrain>(0));
}

[Fact]
public async Task OnActivateAsyncShouldBeCalledOnceOnRemindable()
{
// Arrange

// Act
var grain = await Silo.CreateGrainAsync<ActivationCountWithReminder>(1);
var value = await grain.GetActivationCount();

Assert.Equal(1, value);
}
}