Skip to content

Commit

Permalink
Merge pull request #11829 from guardian/admin-test-timeouts
Browse files Browse the repository at this point in the history
Provide concrete patience configurations to future-based tests
  • Loading branch information
Richard Nguyen committed Feb 3, 2016
2 parents 107934f + 467cc53 commit 9e11025
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ import org.mockito.Matchers._
import org.mockito.Mockito._
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.mock.MockitoSugar
import org.scalatest.time.{Seconds, Span}
import org.scalatest.{DoNotDiscover, Matchers, WordSpec}
import play.api.libs.json.{JsResultException, JsValue, Json}
import test.ConfiguredTestSuite

import scala.concurrent.duration._

@DoNotDiscover class BreakingNewsUpdaterTest extends WordSpec with Matchers with ConfiguredTestSuite with MockitoSugar {

@DoNotDiscover class BreakingNewsUpdaterTest extends WordSpec with Matchers with ConfiguredTestSuite with MockitoSugar with ScalaFutures {
implicit val actorTimeout = Timeout(30.seconds)
implicit override val patienceConfig = PatienceConfig(timeout = Span(5, Seconds), interval = Span(1, Seconds))

def newActorAndMockApi = {
val mockBreakingNewsApi = mock[BreakingNewsApi]
val actorRef = actorSystem.actorOf(BreakingNewsUpdater.props(mockBreakingNewsApi))
Expand All @@ -34,7 +36,7 @@ import scala.concurrent.duration._
when(mockBreakingNewsApi.getBreakingNews) thenThrow new Exception()

val f = actor ? GetAlertsRequest
ScalaFutures.whenReady(f.failed) { e => e shouldBe an[Exception] }
whenReady(f.failed) { e => e shouldBe an[Exception] }
}
}
"content is available" should {
Expand All @@ -45,7 +47,7 @@ import scala.concurrent.duration._
when(mockBreakingNewsApi.getBreakingNews) thenReturn Some(fakeContent)

val f = (actor ? GetAlertsRequest).mapTo[Option[JsValue]]
ScalaFutures.whenReady(f) {
whenReady(f) {
case Some(json) => json shouldBe a[JsValue]
case _ => fail("It should be some JsValue instance")
}
Expand All @@ -72,7 +74,7 @@ import scala.concurrent.duration._
val (actor, mockBreakingNewsApi) = newActorAndMockApi
when(mockBreakingNewsApi.getBreakingNews) thenThrow (new Exception())
val f = (actor ? NewNotificationRequest(notification)).mapTo[NewsAlertNotification]
ScalaFutures.whenReady(f.failed) { e => e shouldBe an[Exception] }
whenReady(f.failed) { e => e shouldBe an[Exception] }
}
}
"succeeds " when {
Expand All @@ -83,7 +85,7 @@ import scala.concurrent.duration._
when(mockBreakingNewsApi.getBreakingNews) thenReturn Some(Json.parse( """{"valid": "json", "but": "not", "breaking": "news"}"""))

val f = (actor ? NewNotificationRequest(notification)).mapTo[NewsAlertNotification]
ScalaFutures.whenReady(f.failed) { e => e shouldBe an[JsResultException] }
whenReady(f.failed) { e => e shouldBe an[JsResultException] }
}
}
"succeeds" when {
Expand Down Expand Up @@ -125,7 +127,7 @@ import scala.concurrent.duration._
when(mockBreakingNewsApi.putBreakingNews(any[JsValue])) thenThrow new Exception()

val f = (actor ? NewNotificationRequest(notification)).mapTo[NewsAlertNotification]
ScalaFutures.whenReady(f.failed) { e => e shouldBe an[Exception] }
whenReady(f.failed) { e => e shouldBe an[Exception] }
}
}
"succeeds" should {
Expand All @@ -135,7 +137,7 @@ import scala.concurrent.duration._
when(mockBreakingNewsApi.putBreakingNews(any[JsValue])) thenReturn true

val f = (actor ? NewNotificationRequest(notification)).mapTo[NewsAlertNotification]
ScalaFutures.whenReady(f) { result =>
whenReady(f) { result =>
result shouldBe a [NewsAlertNotification]
result shouldBe notification
}
Expand Down
2 changes: 1 addition & 1 deletion applications/test/CrosswordDataTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.scalatest.time.{Millis, Span}
"CrosswordData" - {
"fromCrossword should normalize separators for grouped entries" in {

implicit val patienceConfig = PatienceConfig(timeout = scaled(Span(3000, Millis)), interval = scaled(Span(100, Millis)))
implicit val patienceConfig = PatienceConfig(timeout = Span(3000, Millis), interval = Span(100, Millis))
val futureCrossword = controllers.CrosswordPageController.getCrossword("cryptic", 26666)(TestRequest("crosswords/cryptic/26666"))

whenReady(futureCrossword) { result =>
Expand Down

0 comments on commit 9e11025

Please sign in to comment.