Skip to content

Commit

Permalink
Fix racy FunctionRefSpecs (#7169)
Browse files Browse the repository at this point in the history
* Adding verbose debug logging to `FunctionRefSpecs`

* add starting point log

* fixed `FunctionRefSpecs`
  • Loading branch information
Aaronontheweb committed Apr 24, 2024
1 parent a19b825 commit f8a3c88
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/core/Akka.Tests/Actor/FunctionRefSpecs.cs
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
using Akka.Event;
using Akka.TestKit;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -17,9 +18,10 @@ namespace Akka.Tests.Actor
{
public class FunctionRefSpec : AkkaSpec
{

#region internal classes

sealed class GetForwarder : IEquatable<GetForwarder>
private sealed class GetForwarder : IEquatable<GetForwarder>
{
public IActorRef ReplyTo { get; }

Expand All @@ -40,7 +42,7 @@ public bool Equals(GetForwarder other)
public override int GetHashCode() => (ReplyTo != null ? ReplyTo.GetHashCode() : 0);
}

sealed class DropForwarder : IEquatable<DropForwarder>
private sealed class DropForwarder : IEquatable<DropForwarder>
{
public FunctionRef Ref { get; }

Expand All @@ -61,7 +63,7 @@ public bool Equals(DropForwarder other)
public override int GetHashCode() => (Ref != null ? Ref.GetHashCode() : 0);
}

sealed class Forwarded : IEquatable<Forwarded>
private sealed class Forwarded : IEquatable<Forwarded>
{
public object Message { get; }
public IActorRef Sender { get; }
Expand Down Expand Up @@ -90,7 +92,7 @@ public override int GetHashCode()
}
}

sealed class Super : ReceiveActor
private sealed class Super : ReceiveActor, ILogReceive
{
public Super()
{
Expand Down Expand Up @@ -121,8 +123,16 @@ public SupSuper()

#endregion

public FunctionRefSpec(ITestOutputHelper output) : base(output, null)
// create HOCON to enable debug loglevel and have all actors log received messages
private static readonly Config Config = ConfigurationFactory.ParseString(@"
akka.loglevel = DEBUG
akka.loggers = [""Akka.TestKit.TestEventListener, Akka.TestKit""]
akka.actor.debug.receive = on
");

public FunctionRefSpec(ITestOutputHelper output) : base(output)
{
//Sys.Log.Info("Starting FunctionRefSpec");
}

#region top level
Expand All @@ -141,13 +151,11 @@ public async Task FunctionRef_created_by_top_level_actor_must_forward_messages()
public async Task FunctionRef_created_by_top_level_actor_must_be_watchable()
{
var s = SuperActor();
var forwarder = GetFunctionRef(s);

s.Tell(new GetForwarder(TestActor));
var f = await ExpectMsgAsync<FunctionRef>();
Watch(f);
s.Tell(new DropForwarder(f));
await ExpectTerminatedAsync(f);
var forwarder = await GetFunctionRef(s);

await WatchAsync(forwarder);
s.Tell(new DropForwarder(forwarder));
await ExpectTerminatedAsync(forwarder);
}

[Fact]
Expand All @@ -169,7 +177,7 @@ public async Task FunctionRef_created_by_top_level_actor_must_terminate_when_the
var s = SuperActor();
var forwarder = await GetFunctionRef(s);

Watch(forwarder);
await WatchAsync(forwarder);
s.Tell(PoisonPill.Instance);
await ExpectTerminatedAsync(forwarder);
}
Expand Down Expand Up @@ -201,12 +209,10 @@ public async Task FunctionRef_created_by_non_top_level_actor_must_be_watchable()
{
var s = SupSuperActor();
var forwarder = await GetFunctionRef(s);

s.Tell(new GetForwarder(TestActor));
var f = await ExpectMsgAsync<FunctionRef>();
Watch(f);
s.Tell(new DropForwarder(f));
await ExpectTerminatedAsync(f);

await WatchAsync(forwarder);
s.Tell(new DropForwarder(forwarder));
await ExpectTerminatedAsync(forwarder);
}

[Fact]
Expand All @@ -228,7 +234,7 @@ public async Task FunctionRef_created_by_non_top_level_actor_must_terminate_when
var s = SupSuperActor();
var forwarder = await GetFunctionRef(s);

Watch(forwarder);
await WatchAsync(forwarder);
s.Tell(PoisonPill.Instance);
await ExpectTerminatedAsync(forwarder);
}
Expand Down

0 comments on commit f8a3c88

Please sign in to comment.