fix: race condition in downing provider spec (#31213) #31194

This commit is contained in:
Johan Andrén 2022-03-08 12:54:08 +01:00 committed by GitHub
parent 04a6b9f50f
commit ccb542734e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,13 +5,10 @@
package akka.cluster
import java.util.concurrent.atomic.AtomicBoolean
import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import akka.ConfigurationException
import akka.actor.ActorSystem
import akka.actor.Props
@ -19,6 +16,8 @@ import akka.testkit.TestKit.awaitCond
import akka.testkit.TestKit.shutdownActorSystem
import akka.util.unused
import scala.util.control.NonFatal
class FailingDowningProvider(@unused system: ActorSystem) extends DowningProvider {
override val downRemovalMargin: FiniteDuration = 20.seconds
override def downingActorProps: Option[Props] = {
@ -76,18 +75,30 @@ class DowningProviderSpec extends AnyWordSpec with Matchers {
}
"stop the cluster if the downing provider throws exception in props method" in {
val system = ActorSystem(
// race condition where the downing provider failure can be detected and trigger
// graceful shutdown fast enough that creating the actor system throws on constructing
// thread (or slow enough that we have time to try join the cluster before noticing)
val maybeSystem = try {
Some(
ActorSystem(
"auto-downing",
ConfigFactory.parseString("""
akka.cluster.downing-provider-class="akka.cluster.FailingDowningProvider"
""").withFallback(baseConf))
""").withFallback(baseConf)))
} catch {
case NonFatal(_) =>
// expected to sometimes happen
None
}
maybeSystem.foreach { system =>
val cluster = Cluster(system)
cluster.join(cluster.selfAddress)
awaitCond(cluster.isTerminated, 3.seconds)
shutdownActorSystem(system)
}
}
}
}