From 7da906da4fda6c6cd7eb6384bff0aef6b4ba094f Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Sat, 14 Feb 2015 10:22:58 +0100 Subject: = play: ensure that tests use different ports. --- .../kamon/play/instrumentation/RequestInstrumentation.scala | 5 ----- .../test/scala/kamon/play/RequestInstrumentationSpec.scala | 9 +++++---- .../src/test/scala/kamon/play/WSInstrumentationSpec.scala | 11 +++++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala b/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala index e9b2d570..0ec49493 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala @@ -34,11 +34,6 @@ class RequestInstrumentation { @DeclareMixin("play.api.mvc.RequestHeader+") def mixinContextAwareNewRequest: TraceContextAware = TraceContextAware.default - @After("call(* play.api.GlobalSettings.onStart(*)) && args(application)") - def afterApplicationStart(application: play.api.Application): Unit = { - Kamon(Play) - } - @Before("call(* play.api.GlobalSettings.onRouteRequest(..)) && args(requestHeader)") def beforeRouteRequest(requestHeader: RequestHeader): Unit = { import Kamon.tracer diff --git a/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala b/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala index 3e199df6..e0bbede7 100644 --- a/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala +++ b/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala @@ -39,6 +39,7 @@ class RequestInstrumentationSpec extends PlaySpec with OneServerPerSuite { Kamon.start() System.setProperty("config.file", "./kamon-play/src/test/resources/conf/application.conf") + override lazy val port: Port = 19002 val executor = scala.concurrent.ExecutionContext.Implicits.global implicit override lazy val app = FakeApplication(withGlobal = Some(MockGlobalTest), withRoutes = { @@ -126,22 +127,22 @@ class RequestInstrumentationSpec extends PlaySpec with OneServerPerSuite { } "response to the getRouted Action and normalise the current TraceContext name" in { - Await.result(WS.url("http://localhost:19001/getRouted").get(), 10 seconds) + Await.result(WS.url(s"http://localhost:$port/getRouted").get(), 10 seconds) Kamon.metrics.find("getRouted.get", "trace") must not be empty } "response to the postRouted Action and normalise the current TraceContext name" in { - Await.result(WS.url("http://localhost:19001/postRouted").post("content"), 10 seconds) + Await.result(WS.url(s"http://localhost:$port/postRouted").post("content"), 10 seconds) Kamon.metrics.find("postRouted.post", "trace") must not be empty } "response to the showRouted Action and normalise the current TraceContext name" in { - Await.result(WS.url("http://localhost:19001/showRouted/2").get(), 10 seconds) + Await.result(WS.url(s"http://localhost:$port/showRouted/2").get(), 10 seconds) Kamon.metrics.find("show.some.id.get", "trace") must not be empty } "include HttpContext information for help to diagnose possible errors" in { - Await.result(WS.url("http://localhost:19001/getRouted").get(), 10 seconds) + Await.result(WS.url(s"http://localhost:$port/getRouted").get(), 10 seconds) route(FakeRequest(GET, "/default").withHeaders("User-Agent" -> "Fake-Agent")) val httpCtx = TraceLocal.retrieve(HttpContextKey).get diff --git a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala index 9e87da84..577d9bed 100644 --- a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala +++ b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala @@ -35,10 +35,11 @@ class WSInstrumentationSpec extends WordSpecLike with Matchers with OneServerPer import kamon.metric.TraceMetricsSpec.SegmentSyntax System.setProperty("config.file", "./kamon-play/src/test/resources/conf/application.conf") + override lazy val port: Port = 19003 implicit override lazy val app = FakeApplication(withRoutes = { case ("GET", "/async") ⇒ Action { Ok("ok") } case ("GET", "/outside") ⇒ Action { Ok("ok") } - case ("GET", "/inside") ⇒ callWSinsideController("http://localhost:19001/async") + case ("GET", "/inside") ⇒ callWSinsideController(s"http://localhost:$port/async") }) "the WS instrumentation" should { @@ -48,19 +49,19 @@ class WSInstrumentationSpec extends WordSpecLike with Matchers with OneServerPer val snapshot = takeSnapshotOf("GET: /inside") snapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1) snapshot.segments.size should be(1) - snapshot.segment("http://localhost:19001/async", SegmentCategory.HttpClient, Play.SegmentLibraryName).numberOfMeasurements should be(1) + snapshot.segment(s"http://localhost:$port/async", SegmentCategory.HttpClient, Play.SegmentLibraryName).numberOfMeasurements should be(1) } "propagate the TraceContext outside an Action and complete the WS request" in { TraceContext.withContext(newContext("trace-outside-action")) { - Await.result(WS.url("http://localhost:19001/outside").get(), 10 seconds) + Await.result(WS.url(s"http://localhost:$port/outside").get(), 10 seconds) TraceContext.currentContext.finish() } val snapshot = takeSnapshotOf("trace-outside-action") snapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1) snapshot.segments.size should be(1) - snapshot.segment("http://localhost:19001/outside", SegmentCategory.HttpClient, Play.SegmentLibraryName).numberOfMeasurements should be(1) + snapshot.segment(s"http://localhost:$port/outside", SegmentCategory.HttpClient, Play.SegmentLibraryName).numberOfMeasurements should be(1) } } @@ -69,6 +70,8 @@ class WSInstrumentationSpec extends WordSpecLike with Matchers with OneServerPer Kamon.tracer.newContext(name) def takeSnapshotOf(traceName: String): EntitySnapshot = { + // Give some time for async segments to finish. + Thread.sleep(300) val recorder = Kamon.metrics.register(TraceMetrics, traceName).get.recorder val collectionContext = Kamon.metrics.buildDefaultCollectionContext recorder.collect(collectionContext) -- cgit v1.2.3