-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Akka.Router: automatically unpack
IScheduledTellMsg
when being hand…
…led through a router (#7249) * added initial reproduction for #7247 * reproduced #7247 * have fix; working on repro * close #7247 - ensured routers drop IScheduledTellMsg to non-ActorCell'd routees * added timeout back * removed .NET 6-only call --------- Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
- Loading branch information
1 parent
487218c
commit 6bcab70
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="7247BugFixSpec.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2024 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2024 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Routing; | ||
using Akka.TestKit; | ||
using Akka.Util.Internal; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Akka.Tests.Actor.Scheduler; | ||
|
||
public class BugFix7247Spec : AkkaSpec { | ||
public sealed class NoCellActorRef : MinimalActorRef | ||
{ | ||
public NoCellActorRef(ActorPath path, TaskCompletionSource<object> firstMessage) | ||
{ | ||
Path = path; | ||
FirstMessage = firstMessage; | ||
} | ||
|
||
protected override void TellInternal(object message, IActorRef sender) | ||
{ | ||
FirstMessage.TrySetResult(message); | ||
} | ||
|
||
public TaskCompletionSource<object> FirstMessage { get; } | ||
|
||
public override ActorPath Path { get; } | ||
public override IActorRefProvider Provider => throw new NotImplementedException(); | ||
} | ||
|
||
[Fact(DisplayName = "Should not send ScheduledTellMsg envelopes to IActorRefs with no cell")] | ||
public async Task ShouldNotSendScheduledTellMsgToNoCellActorRefs() | ||
{ | ||
// arrange | ||
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
var noCellRef = Sys.As<ExtendedActorSystem>().Provider.CreateFutureRef(tcs); | ||
var router = Sys.ActorOf(Props.Empty.WithRouter(new BroadcastGroup())); | ||
var routee = Routee.FromActorRef(noCellRef); | ||
router.Tell(new AddRoutee(routee)); | ||
|
||
await AwaitAssertAsync(async () => | ||
{ | ||
var allRoutees = await router.Ask<Routees>(GetRoutees.Instance); | ||
allRoutees.Members.Count().ShouldBeGreaterThan(0); | ||
}); | ||
|
||
// act | ||
var msg = "hit"; | ||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(0.5)); | ||
Sys.Scheduler.ScheduleTellOnce(TimeSpan.FromMilliseconds(1), router, msg, ActorRefs.NoSender); | ||
await tcs.Task.WithCancellation(cts.Token); // will time out if we don't get our msg | ||
var respMsg = await tcs.Task; | ||
|
||
// assert | ||
Assert.Equal(msg, respMsg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters