From 92e10991df0d168d1972d4618fcc7e02e2e0a0fa Mon Sep 17 00:00:00 2001 From: Sam Guymer Date: Thu, 17 May 2018 20:11:22 +1000 Subject: Move backend tests into their projects Instead of having a single project which tests all backends, each backend now implements a http test trait along with a streaming test trait if it supports streaming. The test http server has been moved into its own project and is started automatically before running a backends test. This allows each backend to be tested without the possibility of dependency eviction from another backend or the test http server. It also has the side effect of parallelizing the tests providing a speed up when run with multiple cores. --- project/PollingUtils.scala | 45 +++++++++++++++++++++++++++++++++++++++++++++ project/plugins.sbt | 7 +++++-- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 project/PollingUtils.scala (limited to 'project') diff --git a/project/PollingUtils.scala b/project/PollingUtils.scala new file mode 100644 index 0000000..34b92ac --- /dev/null +++ b/project/PollingUtils.scala @@ -0,0 +1,45 @@ +import java.io.FileNotFoundException +import java.net.{ConnectException, URL} + +import scala.concurrent.TimeoutException +import scala.concurrent.duration._ + +object PollingUtils { + + def waitUntilServerAvailable(url: URL): Unit = { + val connected = poll(5.seconds, 250.milliseconds)({ + urlConnectionAvailable(url) + }) + if (!connected) { + throw new TimeoutException(s"Failed to connect to $url") + } + } + + def poll(timeout: FiniteDuration, interval: FiniteDuration)(poll: => Boolean): Boolean = { + val start = System.nanoTime() + + def go(): Boolean = { + if (poll) { + true + } else if ((System.nanoTime() - start) > timeout.toNanos) { + false + } else { + Thread.sleep(interval.toMillis) + go() + } + } + go() + } + + def urlConnectionAvailable(url: URL): Boolean = { + try { + url.openConnection() + .getInputStream + .close() + true + } catch { + case _: ConnectException => false + case _: FileNotFoundException => true // on 404 + } + } +} diff --git a/project/plugins.sbt b/project/plugins.sbt index 1d83f24..b334460 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,5 @@ -addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15") +// using '-coursier' because of https://github.com/lucidsoftware/neo-sbt-scalafmt/issues/64 +addSbtPlugin("com.lucidchart" % "sbt-scalafmt-coursier" % "1.15") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.0") @@ -6,4 +7,6 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0") addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.7") -addSbtPlugin("com.updateimpact" % "updateimpact-sbt-plugin" % "2.1.3") \ No newline at end of file +addSbtPlugin("com.updateimpact" % "updateimpact-sbt-plugin" % "2.1.3") + +addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1") -- cgit v1.2.3