Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix IsNobody for actorref-mock and add unit test for it. #5220

Merged
merged 2 commits into from
Aug 24, 2021
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
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