Skip to content
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
2 changes: 1 addition & 1 deletion src/Orleans.Core/Runtime/InvokableObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private async Task ProcessMessageAsync(Message message)

var filters = _manager.GrainCallFilters;
Response response;
if (filters is { Count: > 0 } || LocalObject is IIncomingGrainCallFilter)
if (filters is { Count: > 0 } || LocalObject.Target is IIncomingGrainCallFilter)
{
var invoker = new GrainMethodInvoker(message, this, request, filters, _manager._interfaceToImplementationMapping, _manager._responseCopier);
await invoker.Invoke();
Expand Down
1 change: 0 additions & 1 deletion test/Orleans.Core.Tests/Runtime/DrainTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ protected virtual async ValueTask<Response> InvokeCoreAsync()
string IInvokable.GetMethodName() => nameof(IInvokable.Invoke);
string IInvokable.GetInterfaceName() => InterfaceType.FullName!;
string IInvokable.GetActivityName() => $"{InterfaceType.FullName}.{nameof(IInvokable.Invoke)}";
// IInvokable permits null metadata; these fixtures use the no-incoming-filters fast path.
MethodInfo IInvokable.GetMethod() => null!;
CancellationToken IInvokable.GetCancellationToken() => RequestCancellationToken;
bool IInvokable.TryCancel() => CancelRequest();
Expand Down
35 changes: 33 additions & 2 deletions test/Orleans.Core.Tests/Runtime/InvokableObjectManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ namespace UnitTests.Runtime;
[TestCategory("BVT")]
public class InvokableObjectManagerTests
{
[Fact]
public async Task Dispatch_InvokesObserverFilterWithoutSystemWideFilters()
{
var observer = new FilteringObserver();
await using var fixture = new ManagerFixture(observer: observer);
var body = new TestInvokable("observer-result");
body.Release.TrySetResult();
var message = fixture.Request(11, body);

fixture.Manager.Dispatch(message);
await fixture.WaitAsync(fixture.StopAsync(), "observer filter and invocation drain");

Assert.Equal(1, observer.InvocationCount);
fixture.AssertSuccess(message, body, "filtered-observer-result");
fixture.AssertResponseCount(1);
}

[Fact]
public async Task StopAsync_WaitsForRunningNormalInvocation()
{
Expand Down Expand Up @@ -545,6 +562,19 @@ public async Task StopAsync_WaitsForTerminalResponseHandling()
}
}

private sealed class FilteringObserver : IGrainObserver, IIncomingGrainCallFilter
{
internal int InvocationCount { get; private set; }

async Task IIncomingGrainCallFilter.Invoke(IIncomingGrainCallContext context)
{
InvocationCount++;
Assert.Same(this, context.Grain);
await context.Invoke();
context.Result = $"filtered-{context.Result}";
}
}

private sealed class ManagerFixture : IAsyncDisposable
{
private readonly ServiceProvider _services;
Expand All @@ -555,9 +585,10 @@ private sealed class ManagerFixture : IAsyncDisposable
private readonly ConcurrentDictionary<CorrelationId, TaskCompletionSource> _responseSignals = new();
private readonly List<Task> _stops = [];

internal ManagerFixture(bool registerObserver = true, [CallerMemberName] string testName = "")
internal ManagerFixture(bool registerObserver = true, IGrainObserver? observer = null, [CallerMemberName] string testName = "")
{
_testName = testName;
Observer = observer ?? new DrainObserver();
var services = new ServiceCollection();
services.AddSerializer();
services.AddLogging();
Expand Down Expand Up @@ -586,7 +617,7 @@ internal ManagerFixture(bool registerObserver = true, [CallerMemberName] string
}
}

internal DrainObserver Observer { get; } = new();
internal IGrainObserver Observer { get; }
internal ObserverGrainId ObserverId { get; } =
ObserverGrainId.Create(ClientGrainId.Create("observer-drain"), IdSpan.Create("observer"));
internal GrainId Sender { get; } = ClientGrainId.Create("observer-drain-sender").GrainId;
Expand Down
Loading