diff --git a/src/OrleansTestKit/TestKitSilo.cs b/src/OrleansTestKit/TestKitSilo.cs index f2d5d2f..8ec5494 100644 --- a/src/OrleansTestKit/TestKitSilo.cs +++ b/src/OrleansTestKit/TestKitSilo.cs @@ -250,15 +250,11 @@ public async Task CreateGrainAsync(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; } } diff --git a/test/OrleansTestKit.Tests/Grains/ActivationCountWithReminder.cs b/test/OrleansTestKit.Tests/Grains/ActivationCountWithReminder.cs new file mode 100644 index 0000000..f4bc08c --- /dev/null +++ b/test/OrleansTestKit.Tests/Grains/ActivationCountWithReminder.cs @@ -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 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); + } + } +} diff --git a/test/OrleansTestKit.Tests/Tests/ActivationGrainTests.cs b/test/OrleansTestKit.Tests/Tests/ActivationGrainTests.cs index 7293d25..80d58c3 100644 --- a/test/OrleansTestKit.Tests/Tests/ActivationGrainTests.cs +++ b/test/OrleansTestKit.Tests/Tests/ActivationGrainTests.cs @@ -32,4 +32,16 @@ public async Task ShouldThrowNotSupportedException() await Assert.ThrowsAsync( async () => await Silo.CreateGrainAsync(0)); } + + [Fact] + public async Task OnActivateAsyncShouldBeCalledOnceOnRemindable() + { + // Arrange + + // Act + var grain = await Silo.CreateGrainAsync(1); + var value = await grain.GetActivationCount(); + + Assert.Equal(1, value); + } }