From 9655ab5cb8d27ec57fd51fa5d88d26357a949591 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sun, 1 Oct 2017 23:18:52 -0700 Subject: Add basic test --- build.sbt | 9 ++--- src/test/resources/application.conf | 7 ++++ src/test/scala/TracingDirectivesSpec.scala | 58 ++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/application.conf create mode 100644 src/test/scala/TracingDirectivesSpec.scala diff --git a/build.sbt b/build.sbt index 2aa0701..dbf4d5d 100644 --- a/build.sbt +++ b/build.sbt @@ -1,11 +1,12 @@ scalaVersion := "2.12.3" libraryDependencies ++= Seq( - "com.typesafe.akka" %% "akka-http" % "10.0.10", + "com.pauldijou" %% "jwt-core" % "0.14.0", + "com.typesafe.akka" %% "akka-http" % "10.0.10", "com.typesafe.akka" %% "akka-http-spray-json" % "10.0.10", - "com.pauldijou" %% "jwt-core" % "0.14.0", - "io.spray" %% "spray-json" % "1.3.3", - "org.scalatest" %% "scalatest" % "3.0.2" % "test", + "io.spray" %% "spray-json" % "1.3.3", + "com.typesafe.akka" %% "akka-http-testkit" % "10.0.10" % "test", + "org.scalatest" %% "scalatest" % "3.0.2" % "test", ) fork in test := true diff --git a/src/test/resources/application.conf b/src/test/resources/application.conf new file mode 100644 index 0000000..acdcc98 --- /dev/null +++ b/src/test/resources/application.conf @@ -0,0 +1,7 @@ +akka { + loglevel = "DEBUG" +} + +tracing { + google.service-account-file="changeme" +} diff --git a/src/test/scala/TracingDirectivesSpec.scala b/src/test/scala/TracingDirectivesSpec.scala new file mode 100644 index 0000000..2454314 --- /dev/null +++ b/src/test/scala/TracingDirectivesSpec.scala @@ -0,0 +1,58 @@ +package xyz.driver.tracing + +import akka.actor._ +import akka.stream._ +import java.nio.file._ +import akka.http.scaladsl.server._ +import akka.http.scaladsl.server.Directives._ +import akka.http.scaladsl.testkit.ScalatestRouteTest +import TracingDirectives._ +import scala.concurrent._ +import scala.concurrent.duration._ + +import org.scalatest._ + +class TracingDirectivesSpec extends FlatSpec with BeforeAndAfterAll with ScalatestRouteTest { + + implicit val tracer = new GoogleTracer( + "driverinc-sandbox", + Paths.get( + system.settings.config.getString("tracing.google.service-account-file")) + ) + + val route: Route = trace(tracer, "example.org") { + pathPrefix("1") { + trace(tracer, "test-sub-trace-1") { + Thread.sleep(2) + trace(tracer, "test-subsub-trace-1") { + Thread.sleep(2) + trace(tracer, "test-subsubsub-trace-1") { + Thread.sleep(10) + complete("ok") + } + } + } + } ~ + pathPrefix("2") { + trace(tracer, "test-sub-trace-2") { + Thread.sleep(20) + complete("ok") + } + } + } + + "Tracer" should "submit" in { + for (i <- 0 until 100) { + Get(s"https://example.org/${i % 2 + 1}") ~> route ~> check { + assert(responseAs[String] == "ok") + } + } + } + + override def afterAll() = { + tracer.queue.complete() + Await.ready(tracer.queue.watchCompletion(), Duration.Inf) + super.afterAll() + } + +} -- cgit v1.2.3