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

Convert null to NoSender. #993

Merged
merged 1 commit into from
May 20, 2015
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
7 changes: 3 additions & 4 deletions src/core/Akka.TestKit.Tests/NoImplicitSenderSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void When_Not_ImplicitSender_then_testActor_is_not_sender()
{
var echoActor = Sys.ActorOf(c => c.ReceiveAny((m, ctx) => TestActor.Tell(ctx.Sender)));
echoActor.Tell("message");
ExpectMsg<IActorRef>(actorRef => actorRef == ActorRefs.NoSender);
ExpectMsg<IActorRef>(actorRef => Equals(actorRef, ActorRefs.NoSender));
}

}
Expand All @@ -31,11 +31,11 @@ public void ImplicitSender_should_have_testActor_as_sender()
{
var echoActor = Sys.ActorOf(c => c.ReceiveAny((m, ctx) => TestActor.Tell(ctx.Sender)));
echoActor.Tell("message");
ExpectMsg<IActorRef>(actorRef => actorRef == TestActor);
ExpectMsg<IActorRef>(actorRef => Equals(actorRef, TestActor));

//Test that it works after we know that context has been changed
echoActor.Tell("message");
ExpectMsg<IActorRef>(actorRef => actorRef == TestActor);
ExpectMsg<IActorRef>(actorRef => Equals(actorRef, TestActor));

}

Expand All @@ -59,6 +59,5 @@ public void ImplicitSender_should_not_change_when_creating_TestActors()
LastSender.ShouldBe(TestActor);
}
}

}

6 changes: 6 additions & 0 deletions src/core/Akka.TestKit/TestKitBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ private TestKitBase(ITestKitAssertions assertions, ActorSystem system, Config co
{
InternalCurrentActorCellKeeper.Current = (ActorCell)((ActorRefWithCell)testActor).Underlying;
}
else if(!(this is TestProbe))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obviously ugly in every possible way. but the testkit currently requires two different behaviors based on type.
(it could be extracted to a virt method, but then again, virt methods from ctors and all that.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put a //TODO: on this line, letting someone in the future know why it's there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a //HACK: on the line below already :)

//HACK: we need to clear the current context when running a No Implicit Sender test as sender from an async test may leak
//but we should not clear the current context when creating a testprobe from a test
{
InternalCurrentActorCellKeeper.Current = null;
}
SynchronizationContext.SetSynchronizationContext(
new ActorCellKeepingSynchronizationContext(InternalCurrentActorCellKeeper.Current));
_testActor = testActor;
Expand Down
5 changes: 4 additions & 1 deletion src/core/Akka/Actor/ActorRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ public ISurrogated FromSurrogate(ActorSystem system)

public void Tell(object message, IActorRef sender)
{
if (sender == null) throw new ArgumentNullException("sender", "A sender must be specified");
if (sender == null)
{
sender = ActorRefs.NoSender;
}

TellInternal(message, sender);
}
Expand Down