-
Notifications
You must be signed in to change notification settings - Fork 554
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
Refactor port logic in healthcheck and tests Suite #14736
Merged
+114
−215
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
import controllers.BreakingNews.{BreakingNewsUpdaterTest, BreakingNewsApiTest} | ||
import controllers.HealthCheck | ||
import org.scalatest.{BeforeAndAfterAll, Suites} | ||
import test.{SingleServerSuite, WithTestWsClient} | ||
package test | ||
|
||
import controllers.BreakingNews.{BreakingNewsApiTest, BreakingNewsUpdaterTest} | ||
import org.scalatest.Suites | ||
|
||
class AdminJobsTestSuite extends Suites ( | ||
new BreakingNewsApiTest, | ||
new BreakingNewsUpdaterTest, | ||
new controllers.NewsAlertControllerTest | ||
) with SingleServerSuite | ||
with BeforeAndAfterAll | ||
with WithTestWsClient { | ||
override lazy val port: Int = new HealthCheck(wsClient).testPort | ||
) with SingleServerSuite { | ||
override lazy val port: Int = 19002 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ package conf | |
import app.LifecycleComponent | ||
import common._ | ||
import org.joda.time.DateTime | ||
import play.api.{Mode, Play} | ||
import play.api.{Environment, Mode, Play} | ||
import play.api.libs.ws.{WSClient, WSResponse} | ||
import play.api.mvc._ | ||
|
||
|
@@ -95,14 +95,7 @@ private[conf] trait HealthCheckFetcher extends ExecutionContexts with Logging { | |
} | ||
} | ||
|
||
protected def fetchResults(testPort: Int, healthChecks: SingleHealthCheck*): Future[Seq[HealthCheckResult]] = { | ||
val defaultPort = 9000 | ||
val port = { | ||
Play.current.mode match { | ||
case Mode.Test => testPort | ||
case _ => defaultPort | ||
} | ||
} | ||
protected def fetchResults(port: Int, healthChecks: SingleHealthCheck*): Future[Seq[HealthCheckResult]] = { | ||
val baseUrl = s"http://localhost:$port" | ||
Future.sequence(healthChecks.map(fetchResult(baseUrl, _))) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👋 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
|
@@ -114,10 +107,10 @@ private[conf] class HealthCheckCache(val wsClient: WSClient) extends HealthCheck | |
protected val cache = AkkaAgent[List[HealthCheckResult]](List[HealthCheckResult]()) | ||
def get(): List[HealthCheckResult] = cache.get() | ||
|
||
def refresh(testPort: Int, healthChecks: SingleHealthCheck*): Future[List[HealthCheckResult]] = { | ||
def refresh(port: Int, healthChecks: SingleHealthCheck*): Future[List[HealthCheckResult]] = { | ||
val alreadyFetched = noRefreshNeededResults | ||
val toFetch: Seq[SingleHealthCheck] = healthChecks.filterNot(h => alreadyFetched.map(_.url).contains(h.path)) | ||
fetchResults(testPort, toFetch:_*).flatMap(fetchedResults => cache.alter(fetchedResults.toList ++ alreadyFetched)) | ||
fetchResults(port, toFetch:_*).flatMap(fetchedResults => cache.alter(fetchedResults.toList ++ alreadyFetched)) | ||
} | ||
|
||
private def noRefreshNeededResults(): List[HealthCheckResult] = { | ||
|
@@ -136,7 +129,9 @@ trait HealthCheckController extends Controller { | |
def healthCheck(): Action[AnyContent] | ||
} | ||
|
||
class CachedHealthCheck(policy: HealthCheckPolicy, wsClient: WSClient, testPort: Int, healthChecks: SingleHealthCheck*) extends HealthCheckController with Results with ExecutionContexts with Logging { | ||
class CachedHealthCheck(policy: HealthCheckPolicy, healthChecks: SingleHealthCheck*) | ||
(implicit wsClient: WSClient) | ||
extends HealthCheckController with Results with ExecutionContexts with Logging { | ||
|
||
private[conf] val cache: HealthCheckCache = new HealthCheckCache(wsClient) | ||
|
||
|
@@ -152,6 +147,8 @@ class CachedHealthCheck(policy: HealthCheckPolicy, wsClient: WSClient, testPort: | |
case HealthCheckPolicy.Any => anySuccessful(results) | ||
} | ||
|
||
val port: Int = 9000 | ||
|
||
def healthCheck(): Action[AnyContent] = Action.async { | ||
Future.successful { | ||
val results = cache.get | ||
|
@@ -163,14 +160,14 @@ class CachedHealthCheck(policy: HealthCheckPolicy, wsClient: WSClient, testPort: | |
} | ||
} | ||
|
||
def runChecks: Future[Unit] = cache.refresh(testPort, healthChecks:_*).map(_ => Nil) | ||
def runChecks: Future[Unit] = cache.refresh(port, healthChecks:_*).map(_ => Nil) | ||
} | ||
|
||
case class AllGoodCachedHealthCheck(wsClient: WSClient, testPort: Int, healthChecks: SingleHealthCheck*) | ||
extends CachedHealthCheck(HealthCheckPolicy.All, wsClient, testPort, healthChecks:_*) | ||
case class AllGoodCachedHealthCheck(healthChecks: SingleHealthCheck*)(implicit wsClient: WSClient) | ||
extends CachedHealthCheck(HealthCheckPolicy.All, healthChecks:_*) | ||
|
||
case class AnyGoodCachedHealthCheck(wsClient: WSClient, testPort: Int, healthChecks: SingleHealthCheck*) | ||
extends CachedHealthCheck(HealthCheckPolicy.Any, wsClient, testPort, healthChecks:_*) | ||
case class AnyGoodCachedHealthCheck(healthChecks: SingleHealthCheck*)(implicit wsClient: WSClient) | ||
extends CachedHealthCheck(HealthCheckPolicy.Any, healthChecks:_*) | ||
|
||
class CachedHealthCheckLifeCycle( | ||
healthCheckController: CachedHealthCheck, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for clarity or is it needed for the override to compile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Necessary, otherwise the
port
val in the constructor closure shadows the testport