Skip to content

Commit

Permalink
Merge pull request #993 from rogeralsing/null-means-no
Browse files Browse the repository at this point in the history
Convert null to NoSender.
  • Loading branch information
Aaronontheweb committed May 20, 2015
2 parents 85d3d0c + e5b6f82 commit 452dde1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
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))
//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

0 comments on commit 452dde1

Please sign in to comment.