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

Adds support to Orleans.Analyzers for generic attributes #8352

Merged
merged 2 commits into from Mar 21, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Orleans.Analyzers/SyntaxHelpers.cs
Expand Up @@ -13,6 +13,7 @@ internal static class SyntaxHelpers
{
IdentifierNameSyntax id => id.Identifier.Text,
QualifiedNameSyntax qualified => qualified.Right.Identifier.Text,
GenericNameSyntax generic => generic.Identifier.Text,
_ => throw new NotSupportedException()
};

Expand Down
32 changes: 32 additions & 0 deletions test/Grains/TestGrains/StuckGrain.cs
Expand Up @@ -20,6 +20,9 @@ public class StuckGrain : Grain, IStuckGrain
private readonly ILogger<StuckGrain> _log;
private bool isDeactivatingBlocking = false;

private static ConcurrentDictionary<GrainId, ManualResetEventSlim> blockingMREMap =
new ConcurrentDictionary<GrainId, ManualResetEventSlim>();

public StuckGrain(ILogger<StuckGrain> log)
{
_log = log;
Expand All @@ -38,6 +41,33 @@ public static bool Release(Guid key)
}
}

public static Task WaitForDeactivationStart(GrainId key)
{
if (!blockingMREMap.TryGetValue(key, out var mre) || mre == null)
throw new InvalidOperationException();


return Task.Run(() => mre.Wait(1000));
}

public static void SetDeactivationStarted(GrainId key)
{
if (!blockingMREMap.TryGetValue(key, out var mre) || mre == null)
return;

mre.Set();
}

public static void BlockCallingTestUntilDeactivation(GrainId key)
{
if (!blockingMREMap.TryGetValue(key, out var mre) || mre == null)
mre = new ManualResetEventSlim(false);
else if (mre != null)
mre.Reset();

blockingMREMap[key] = mre;
}

public static bool IsActivated(Guid key)
{
return grains.Contains(key);
Expand Down Expand Up @@ -77,6 +107,7 @@ public Task<bool> DidActivationTryToStart(GrainId id)
public Task BlockingDeactivation()
{
isDeactivatingBlocking = true;
BlockCallingTestUntilDeactivation(this.GetGrainId());
DeactivateOnIdle();
return Task.CompletedTask;
}
Expand Down Expand Up @@ -116,6 +147,7 @@ public override Task OnDeactivateAsync(DeactivationReason reason, CancellationTo
{
_log.LogInformation(reason.Exception, "Deactivating ReasonCode: {ReasonCode} Description: {ReasonText}", reason.ReasonCode, reason.Description);

SetDeactivationStarted(this.GetGrainId());
if (isDeactivatingBlocking) return RunForever();

var key = this.GetPrimaryKey();
Expand Down
3 changes: 3 additions & 0 deletions test/TesterInternal/OrleansRuntime/StuckGrainTests.cs
Expand Up @@ -10,6 +10,7 @@
using Xunit;
using System.Diagnostics;
using Orleans.Runtime;
using UnitTests.Grains;

namespace UnitTests.StuckGrainTests
{
Expand Down Expand Up @@ -109,6 +110,8 @@ public async Task StuckGrainTest_StuckDetectionOnDeactivation()
var stuckGrain = this.fixture.GrainFactory.GetGrain<IStuckGrain>(id);
await stuckGrain.BlockingDeactivation();

await StuckGrain.WaitForDeactivationStart(stuckGrain.GetGrainId());

for (var i = 0; i < 3; i++)
{
await Assert.ThrowsAsync<TimeoutException>(
Expand Down