OrleansTestKit
OrleansTestKit copied to clipboard
IRemindable grains are always activated twice by CreateGrainAsync
IRemindable grains are always activated twice by silo.CreateGrainAsync, this is happening because of this changes
repro:
public class RemindableGrain : Grain, IGrainWithIntegerKey, IRemindable
{
public int Times = 0;
public override Task OnActivateAsync(CancellationToken cancellationToken)
{
Times++;
return Task.CompletedTask;
}
public Task ReceiveReminder(string reminderName, TickStatus status) => Task.CompletedTask;
}
public class ReproTests
{
[Fact]
public async Task Test()
{
var silo = new TestKitSilo();
var grain = await silo.CreateGrainAsync<RemindableGrain>(1);
Assert.Equal(1, grain.Times);
}
}
result:
Assert.Equal() Failure
Expected: 1
Actual: 2
tested on OrleansTestKit 8.0.0/4.0.0
4.0.0-beta.3 works fine
CreateGrainAsync<T>(IdSpan identity, CancellationToken cancellation = default) in TestKitSilo has an if branch for the IRemindables which activates and adds to active grains, then immediately after that scope those two actions are done again.
if (grain is IRemindable)
{
// 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;
I'm not github savvy nor have the time to fix this, so here's a freebie for someone with spare time.
at a quick glance the if IRemindable just needs a else block