Skip to content

Commit

Permalink
Fix method signature change in RuntimeContext 7.2.5 (#157)
Browse files Browse the repository at this point in the history
* Fix method signature change in RuntimeContext

* Proper version
  • Loading branch information
spingee committed May 19, 2024
1 parent 02eb74e commit eee8bd0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/OrleansTestKit/OrleansTestKit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageTags>Orleans Cloud-Computing Actor-Model Actors Distributed-Systems C# .NET Test Testing</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>4.0.0</Version>
<Version>4.0.1</Version>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -24,9 +24,9 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Orleans.Reminders" Version="7.2.4" />
<PackageReference Include="Microsoft.Orleans.Streaming" Version="7.2.4" />
<PackageReference Include="Microsoft.Orleans.Runtime" Version="7.2.4" />
<PackageReference Include="Microsoft.Orleans.Reminders" Version="7.2.5" />
<PackageReference Include="Microsoft.Orleans.Streaming" Version="7.2.5" />
<PackageReference Include="Microsoft.Orleans.Runtime" Version="7.2.5" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
8 changes: 5 additions & 3 deletions src/OrleansTestKit/Reminders/ReminderContextHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ private ReminderContextHolder()
_slim = new SemaphoreSlim(1);
var assembly = typeof(GrainId).Assembly;
var contextType = assembly.GetType(RuntimeNamespace)!;
_runtimeContextMethod = contextType.GetMethod(RuntimeMethod, BindingFlags.NonPublic | BindingFlags.Static, new Type[] { typeof(IGrainContext) })!;
_runtimeContextMethod = contextType.GetMethod(RuntimeMethod,
BindingFlags.NonPublic | BindingFlags.Static,
new Type[] { typeof(IGrainContext), typeof(IGrainContext).MakeByRefType() })!;
}

public static ReminderContextHolder Instance =>
Expand All @@ -33,7 +35,7 @@ public void ReleaseReminderContext()
{
try
{
_runtimeContextMethod.Invoke(null, new object?[] { null });
_runtimeContextMethod.Invoke(null, new object?[] { null, null });
}
finally
{
Expand All @@ -44,6 +46,6 @@ public void ReleaseReminderContext()
public async Task SetReminderContext(IGrainContext context, CancellationToken token = default)
{
await _slim.WaitAsync(token);
_runtimeContextMethod.Invoke(null, new object[] { context });
_runtimeContextMethod.Invoke(null, new object[] { context, null });
}
}
19 changes: 12 additions & 7 deletions src/OrleansTestKit/Utilities/RuntimeContextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,33 @@ namespace Orleans.TestKit.Reminders;

internal sealed class RuntimeContextManager
{
public delegate void SetExecutionContextDelegate(IGrainContext? newContext, out IGrainContext currentContext);

private RuntimeContextManager()
{
var assembly = typeof(GrainId).Assembly;
var contextType = assembly.GetType("Orleans.Runtime.RuntimeContext")!;

SetExecutionContext = contextType
.GetMethod("SetExecutionContext", BindingFlags.NonPublic | BindingFlags.Static, new Type[] { typeof(IGrainContext) })!
.CreateDelegate<Action<IGrainContext?>>()
;
var methodInfo = contextType
.GetMethod("SetExecutionContext",
BindingFlags.NonPublic | BindingFlags.Static,
new Type[] { typeof(IGrainContext), typeof(IGrainContext).MakeByRefType() });
SetExecutionContext = methodInfo!
.CreateDelegate<SetExecutionContextDelegate>()
;
}

public static RuntimeContextManager Instance { get; } = new RuntimeContextManager();

public Action<IGrainContext?> SetExecutionContext { get; }
public SetExecutionContextDelegate SetExecutionContext { get; }

public static IDisposable StartExecutionContext(IGrainContext context) => new RuntimeContextScope(context);

public void ResetExecutionContext() => SetExecutionContext(null);
public void ResetExecutionContext() => SetExecutionContext(null, out _);

private sealed class RuntimeContextScope : IDisposable
{
public RuntimeContextScope(IGrainContext context) => Instance.SetExecutionContext(context);
public RuntimeContextScope(IGrainContext context) => Instance.SetExecutionContext(context, out _);

public void Dispose() => Instance.ResetExecutionContext();
}
Expand Down
2 changes: 1 addition & 1 deletion test/OrleansTestKit.Tests/OrleansTestKit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.CodeCoverage" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.2.4" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.2.5" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.6.5" />
Expand Down

0 comments on commit eee8bd0

Please sign in to comment.