Workaround for Initialization race in MultiNodeSpec, see #2143

This commit is contained in:
Patrik Nordwall 2012-05-29 11:41:22 +02:00
parent 276b3f8ea3
commit 66efe504da
2 changed files with 25 additions and 12 deletions

View file

@ -20,7 +20,7 @@ import akka.remote.testkit.MultiNodeConfig
object TestConductorMultiJvmSpec extends MultiNodeConfig {
commonConfig(debugConfig(on = false))
val master = role("master")
val slave = role("slave")
}
@ -34,19 +34,19 @@ class TestConductorSpec extends MultiNodeSpec(TestConductorMultiJvmSpec) with Im
def initialParticipants = 2
runOn(master) {
system.actorOf(Props(new Actor {
def receive = {
case x testActor ! x; sender ! x
}
}), "echo")
}
val echo = system.actorFor(node(master) / "user" / "echo")
lazy val echo = system.actorFor(node(master) / "user" / "echo")
"A TestConductor" must {
"enter a barrier" in {
runOn(master) {
system.actorOf(Props(new Actor {
def receive = {
case x testActor ! x; sender ! x
}
}), "echo")
}
testConductor.enter("name")
}

View file

@ -14,6 +14,7 @@ import com.typesafe.config.ConfigFactory
import akka.dispatch.Await.Awaitable
import akka.dispatch.Await
import akka.util.Duration
import akka.util.NonFatal
import akka.actor.ActorPath
import akka.actor.RootActorPath
import akka.remote.testconductor.RoleName
@ -214,8 +215,20 @@ abstract class MultiNodeSpec(val myself: RoleName, _system: ActorSystem, roles:
val deployString = (str /: replacements) {
case (base, r @ Replacement(tag, _))
base.indexOf(tag) match {
case -1 base
case start base.replace(tag, r.addr)
case -1 base
case start
val replaceWith = try
r.addr
catch {
case NonFatal(e)
// might happen if all test cases are ignored (excluded) and
// controller node is finished/exited before r.addr is run
// on the other nodes
val unresolved = "akka://unresolved-replacement-" + r.role.name
log.warning(unresolved + " due to: " + e.getMessage)
unresolved
}
base.replace(tag, replaceWith)
}
}
import scala.collection.JavaConverters._