Skip to content

Commit

Permalink
fix IsNobody for actorref-mock and add unit test for it. (#5220)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Stannard <[email protected]>
  • Loading branch information
Zetanova and Aaronontheweb authored Aug 24, 2021
1 parent e38295b commit e96833b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/core/Akka.Tests/Actor/ActorRefSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Akka.Serialization;
using Akka.TestKit;
using Akka.TestKit.TestActors;
using Akka.Util;
using Xunit;

namespace Akka.Tests.Actor
Expand Down Expand Up @@ -290,13 +291,54 @@ public void An_ActorRef_should_never_have_a_null_Sender_Bug_1212()
ExpectNoMsg();
}

[Fact]
public void An_ActorRef_Mock_should_be_like_Nobody()
{
var mock = new ActorRefMock();

mock.Tell("dummy");

mock.IsNobody().ShouldBeTrue();
}

private void VerifyActorTermination(IActorRef actorRef)
{
var watcher = CreateTestProbe();
watcher.Watch(actorRef);
watcher.ExpectTerminated(actorRef, TimeSpan.FromSeconds(20));
}

private sealed class ActorRefMock : IActorRef
{
public ActorRefMock() { }

ActorPath IActorRef.Path => null;

int IComparable<IActorRef>.CompareTo(IActorRef other)
{
throw new NotSupportedException();
}

int IComparable.CompareTo(object obj)
{
throw new NotSupportedException();
}

bool IEquatable<IActorRef>.Equals(IActorRef other)
{
throw new NotSupportedException();
}

void ICanTell.Tell(object message, IActorRef sender)
{
}

ISurrogate ISurrogated.ToSurrogate(ActorSystem system)
{
throw new NotSupportedException();
}
}

private class NestingActor : ActorBase
{
internal readonly IActorRef Nested;
Expand Down
3 changes: 2 additions & 1 deletion src/core/Akka/Actor/ActorRef.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public static class ActorRefExtensions
/// <returns><c>true</c> if the <paramref name="actorRef"/> is valid; otherwise <c>false</c>.</returns>
public static bool IsNobody(this IActorRef actorRef)
{
return actorRef == null || actorRef is Nobody || actorRef is DeadLetterActorRef || (actorRef.Path.Uid == 0 && actorRef.Path.Name == "deadLetters");
return actorRef is null || actorRef is Nobody || actorRef is DeadLetterActorRef
|| actorRef.Path is null || (actorRef.Path.Uid == 0 && actorRef.Path.Name == "deadLetters");
}

/// <summary>
Expand Down

0 comments on commit e96833b

Please sign in to comment.