Harden BindCanonicalAddressSpec (#25404)

The randomly selected port by Artery could be the same as the randomly
selected port the test generates.

Fixes #25403
This commit is contained in:
Christopher Batey 2018-08-20 13:56:11 +01:00 committed by GitHub
parent 17aabf1f00
commit 7299d6b26c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View file

@ -30,7 +30,7 @@ class BoundAddressesExtension(val system: ExtendedActorSystem) extends Extension
*/ */
def boundAddresses: Map[String, Set[Address]] = system.provider def boundAddresses: Map[String, Set[Address]] = system.provider
.asInstanceOf[RemoteActorRefProvider].transport match { .asInstanceOf[RemoteActorRefProvider].transport match {
case artery: ArteryTransport Map((ArteryTransport.ProtocolName Set(artery.bindAddress.address))) case artery: ArteryTransport Map(ArteryTransport.ProtocolName Set(artery.bindAddress.address))
case remoting: Remoting remoting.boundAddresses case remoting: Remoting remoting.boundAddresses
} }
} }

View file

@ -5,7 +5,7 @@
package akka.remote.artery package akka.remote.artery
import com.typesafe.config.{ Config, ConfigFactory } import com.typesafe.config.{ Config, ConfigFactory }
import akka.actor.ActorSystem import akka.actor.{ ActorSystem, Address }
import akka.remote.transport.netty.NettyTransportSpec._ import akka.remote.transport.netty.NettyTransportSpec._
import scala.concurrent.Await import scala.concurrent.Await
@ -46,8 +46,16 @@ trait BindCanonicalAddressBehaviors {
implicit val sys = ActorSystem("sys", config.withFallback(commonConfig)) implicit val sys = ActorSystem("sys", config.withFallback(commonConfig))
getExternal should ===(address.toAkkaAddress("akka")) getExternal should ===(address.toAkkaAddress("akka"))
getInternal should not contain (address.toAkkaAddress("akka")) // May have selected the same random port - bind another in that case while the other still has the canonical port
val internals = if (getInternal.collect { case Address(_, _, _, Some(port)) port }.toSeq.contains(address.getPort)) {
val sys2 = ActorSystem("sys", config.withFallback(commonConfig))
val secondInternals = getInternal()(sys2)
Await.result(sys2.terminate(), Duration.Inf)
secondInternals
} else {
getInternal
}
internals should not contain address.toAkkaAddress("akka")
Await.result(sys.terminate(), Duration.Inf) Await.result(sys.terminate(), Duration.Inf)
} }
@ -98,13 +106,13 @@ trait BindCanonicalAddressBehaviors {
class BindCanonicalAddressSpec extends WordSpec with Matchers with BindCanonicalAddressBehaviors { class BindCanonicalAddressSpec extends WordSpec with Matchers with BindCanonicalAddressBehaviors {
s"artery with aeron-udp transport" should { s"artery with aeron-udp transport" should {
behave like arteryConnectionTest("aeron-udp", true) behave like arteryConnectionTest("aeron-udp", isUDP = true)
} }
s"artery with tcp transport" should { s"artery with tcp transport" should {
behave like arteryConnectionTest("tcp", false) behave like arteryConnectionTest("tcp", isUDP = false)
} }
s"artery with tls-tcp transport" should { s"artery with tls-tcp transport" should {
behave like arteryConnectionTest("tls-tcp", false) behave like arteryConnectionTest("tls-tcp", isUDP = false)
} }
} }
@ -114,7 +122,7 @@ object BindCanonicalAddressSpec {
akka { akka {
actor.provider = remote actor.provider = remote
remote.artery.enabled = true remote.artery.enabled = true
remote.artery.transport = "${transport}" remote.artery.transport = "$transport"
} }
""") """)
} }