diff --git a/akka-docs/scala/testing.rst b/akka-docs/scala/testing.rst index 871e708fd3..d21e1f4c5d 100644 --- a/akka-docs/scala/testing.rst +++ b/akka-docs/scala/testing.rst @@ -387,6 +387,23 @@ invariably lead to spurious test failures on the heavily loaded Jenkins server internally scaled by a factor taken from ``akka.conf``, ``akka.test.timefactor``, which defaults to 1. +Resolving Conflicts with Implicit ActorRef +------------------------------------------ + +The :class:`TestKit` trait contains an implicit value of type :class:`ActorRef` +to enable the magic reply handling. This value is named ``self`` so that e.g. +anonymous actors may be declared within a test class without having to care +about the ambiguous implicit issues which would otherwise arise. If you find +yourself in a situation where the implicit you need comes from a different +trait than :class:`TestKit` and is not named ``self``, then use +:class:`TestKitLight`, which differs only in not having any implicit members. +You would then need to make an implicit available in locally confined scopes +which need it, e.g. different test cases. If this cannot be done, you will need +to resort to explicitly specifying the sender reference:: + + val actor = actorOf[MyWorker].start() + actor.!(msg)(testActor) + Using Multiple Probe Actors --------------------------- diff --git a/akka-testkit/src/main/scala/akka/testkit/TestKit.scala b/akka-testkit/src/main/scala/akka/testkit/TestKit.scala index 5992e783a1..4f4639c150 100644 --- a/akka-testkit/src/main/scala/akka/testkit/TestKit.scala +++ b/akka-testkit/src/main/scala/akka/testkit/TestKit.scala @@ -88,7 +88,7 @@ class TestActor(queue: BlockingDeque[TestActor.Message]) extends Actor with FSM[ * @author Roland Kuhn * @since 1.1 */ -trait TestKit { +trait TestKitLight { import TestActor.{ Message, RealMessage, NullMessage } @@ -99,7 +99,7 @@ trait TestKit { * ActorRef of the test actor. Access is provided to enable e.g. * registration as message target. */ - implicit val testActor = actorOf(new TestActor(queue)).start() + val testActor = actorOf(new TestActor(queue)).start() /** * Implicit sender reference so that replies are possible for messages sent @@ -550,6 +550,10 @@ trait TestKit { private def format(u: TimeUnit, d: Duration) = "%.3f %s".format(d.toUnit(u), u.toString.toLowerCase) } +trait TestKit extends TestKitLight { + implicit val self = testActor +} + /** * TestKit-based probe which allows sending, reception and reply. */