Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase patience config #860

Merged
merged 4 commits into from
Feb 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package akka.cluster.http.management.scaladsl
// TODO has to be in akka.cluster because it touches Reachability which is private[akka.cluster]

import scala.collection.immutable._
import scala.concurrent.Promise

import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Address
Expand All @@ -29,23 +31,30 @@ import akka.management.cluster._
import akka.management.cluster.scaladsl.ClusterHttpManagementRoutes
import akka.management.scaladsl.ManagementRouteProviderSettings
import akka.stream.scaladsl.Sink
import akka.util.{ ByteString, Timeout }
import akka.util.ByteString
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import org.mockito.Matchers._
import org.mockito.Mockito._
import org.scalatest.concurrent.Eventually
import org.scalatest.concurrent.PatienceConfiguration.{ Timeout => ScalatestTimeout }
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.time.Millis
import org.scalatest.time.Seconds
import org.scalatest.time.Span
import org.scalatest.wordspec.AnyWordSpecLike

import scala.concurrent.Promise

class ClusterHttpManagementRoutesSpec
extends AnyWordSpecLike
with Matchers
with ScalatestRouteTest
with ClusterHttpManagementJsonProtocol
with ScalaFutures {
with ScalaFutures
with Eventually {

override implicit def patienceConfig: PatienceConfig =
PatienceConfig(timeout = Span(3, Seconds), interval = Span(50, Millis))

"Http Cluster Management Routes" should {
"return list of members with cluster leader and oldest" when {
Expand Down Expand Up @@ -119,9 +128,11 @@ class ClusterHttpManagementRoutesSpec
val mockedCluster = mock(classOf[Cluster])
doNothing().when(mockedCluster).join(any[Address])

Post("/cluster/members/", urlEncodedForm) ~> ClusterHttpManagementRoutes(mockedCluster) ~> check {
status shouldEqual StatusCodes.OK
responseAs[ClusterHttpManagementMessage] shouldEqual ClusterHttpManagementMessage(s"Joining $address")
eventually {
Post("/cluster/members/", urlEncodedForm) ~> ClusterHttpManagementRoutes(mockedCluster) ~> check {
status shouldEqual StatusCodes.OK
responseAs[ClusterHttpManagementMessage] shouldEqual ClusterHttpManagementMessage(s"Joining $address")
}
}
}
}
Expand Down Expand Up @@ -327,6 +338,7 @@ class ClusterHttpManagementRoutesSpec

"calling GET /cluster/shard_regions/{name}" in {
import scala.concurrent.duration._

import akka.pattern.ask

val config = ConfigFactory.parseString(
Expand Down Expand Up @@ -443,7 +455,7 @@ class ClusterHttpManagementRoutesSpec
.futureValue(t)
responseGetDomainEvents.status shouldEqual StatusCodes.OK
val responseGetDomainEventsData = responseGetDomainEvents.entity.dataBytes
.takeWithin(100.millis)
.takeWithin(500.millis)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this is the actual fix since taking events during a longer period is likely to obtain the one we're looking for.

.fold(ByteString.empty)(_ ++ _)
.runWith(Sink.head)
.futureValue
Expand All @@ -452,6 +464,9 @@ class ClusterHttpManagementRoutesSpec

responseGetDomainEventsData should include("event:MemberUp")

// TODO: prefer Coordinated shutdown to prevent ubinding the server before the client is
// shut down which causes:
// java.lang.IllegalStateException: Pool shutdown unexpectedly
binding.unbind().futureValue
system.terminate()
}
Expand Down